1

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.

2
  • Looks like you are using Joomla, why not use the built in breadcrumbs and save yourself the time and effort?? Commented Sep 11, 2011 at 19:19
  • Joomla 1.5 breadcrumb does not work properly. I think it is buggy. So I've done custom coding to display the breadcrumb myself. Commented Sep 12, 2011 at 3:13

3 Answers 3

1

You can try using a simple associative array. PHP natively allows the use of strings for array indices. I'm not sure about the underlying data structure, but you could always benchmark it.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

Thanks but my main question is how those urls( as mentioned above) will spread withnin the associative array. In the worst case all url's go into single bucket. How to make them spread evenly?
This is a hash table, so the keys are hashed to achieve even distribution, you don't have to manage this your self. FYI this is the hash function
0

You can use php with redis if you want to use data structure here for faster output.You can check below extension.

https://github.com/phpredis/phpredis

Hope this would help you out.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.