PHP数据结构的建议需要 [英] php data structures suggestion needed

查看:111
本文介绍了PHP数据结构的建议需要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有网址的1000的形式为:

<$p$p><$c$c>http://www.downloadformsindia.com/index.php?option=com_download&e=n&task=showpage&file=Forms%252Fmisc%252Ficc%252Fhdfcbank%252FBlocking%20ATM%20and%20Debit%20Card%20Form.pdf&title=HDFC%3ABlocking%2BATM%2B%26%2BDebit%2BCard%2BForm&$c$c=igi

对于每个URL我想存储相关的痕迹。因此,只要是去过这样一个URL,我将展示它的痕迹。

所以,我希望有一个映射到URL的存储与面包屑。 URL的将是散列键。

我的问题是,我没有在PHP但仅限于C ++ / Java或Perl的工作。
我想包含一个哈希说,在一个PHP变量,我序列化到永久存放在磁盘上万这样的值。
对于每一个页面加载,我想创建动态存储的散列变量和搜索URL作为哈希的关键。
它应该是pretty快。我不知道如果PHP使用哈希树映射或哈希映射。好吧,如果我去了哈希映射,我怎么均匀地分布在网址的关键,使所有的网址就进入单斗?

任何想法表示欢迎。


解决方案

PHP的关联数组哈希表(哈希映射)。

他们接受任何字符串作为键,这样你就可以直接使用的URL的钥匙。

您可以只创建一个数组,并分配给它这样的:

  $数据=阵列();
$数据[$ URL] = $ data_for_this_url;

和使用 导出连载() 甚至 var_export() (以后可能会更快导入,特别是与运算code缓存)。

这是一个哈希表,所以密钥散列以均匀地分布在表中。根据需要,以避免过多的碰撞表的增长。您不必采取这种照顾。

I've 1000's of url's in the form of:

http://www.downloadformsindia.com/index.php?option=com_download&e=n&task=showpage&file=Forms%252Fmisc%252Ficc%252Fhdfcbank%252FBlocking%20ATM%20and%20Debit%20Card%20Form.pdf&title=HDFC%3ABlocking%2BATM%2B%26%2BDebit%2BCard%2BForm&code=igi

For each url I want to store related breadcrumb. So whenever an URL like this is visited I'll show it's breadcrumb.

So I want a map to store url's with breadcrumbs. URL's will be hash key.

My problem is that I've not worked on PHP but only on C++/Java or Perl. I want a hash containing say 10 thousand such values in a php variable, which I'd serialize it to store it permanently on the disk. For each page load, I'd create the stored hash variable on the fly and search for the url as a key of the hash. It should be pretty fast. I'm not sure if PHP hash uses a Tree Map or Hash Map. Ok if I go for Hash map, how do I evenly distribute the url's as key so that all the url's do get into single bucket?

Any ideas welcome.

解决方案

PHP's associative arrays are Hash tables (Hash maps).

They accept any string as key, so you can use the URLs directly for the keys.

You can just create an array and assign to it like this:

$data = array();
$data[$url] = $data_for_this_url;

And export it with serialize() or even var_export() (the later may be faster to import, especially with an opcode cache).

This is a hash table, so the keys are hashed to be evenly distributed in the table. The table grows as needed to avoid too much collisions. You don't have to take care of this.

这篇关于PHP数据结构的建议需要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆