| 
	
 | 
 Posted by Erwin Moller on 05/16/07 12:01 
Taras_96 wrote: 
 
> Hi everyone, 
>  
> I'm wondering if anyone knows whether PHP does some indexing behind 
> the scenes to make array searches faster. 
>  
> What I have is an array of around 100 000 elements, and I have a list 
> of 1000 given element which I need to see whether they contained in 
> the array. This means 1000 searches on an array of size 100 000. I'm 
> hoping that PHP indexes it's keys using a binary tree or 
> something.. :) 
 
Hi, 
 
PHP used hashing.  
I understand it is all very fast, but it was many years ago I learned the  
logic behind it, so I forgot all about the linked lists and stuff like  
that, and cannot be of help there. 
 
But looking up 1000 values inside 100.000 can easily be done by using  
specialized array functions, like: 
array_diff() 
and 
array_intersects() 
 
Look them up at www.php.net. 
 
You can bet the alghoritm used behind the scenes is optimized C-code, and  
probably unbeatable by your own routines. 
 
I would give them a shot first. If still too slow, ask again. :-) 
 
Regards, 
Erwin Moller 
 
>  
> Thanks 
>  
> Taras
 
  
Navigation:
[Reply to this message] 
 |