Reply to Re: compare

Your name:

Reply:


Posted by Bob Stearns on 04/10/06 00:20

talthen.z-serwera.o2@nospam.pl wrote:
> "Piet" <p.potjer@hccnet.nl>
>
>>How can I stop a function in PHP?
>>
>>When comparing data I want to stop the function on a hit.
>>Function compare($data) {
>>
>>For ($n=1; $n<=10000; $n++) {
>> For ($m=1; $m<=10000; $m++) {
>> If $data[$n]==data[$m] {
>> .
>> Exit function, or exit for.. --- but how?
>> }
>> }
>>}
>
>
> 1. "Function", "If" and "For" should be lowercase
> 2. To break a loop- "break;"
> 3. To exit from function: "die('message explainging the reason');". You can
> use "exit()" alias or just "return 0;".
> 4. For string comparison you can use substr_compare- should be much faster
> then comparing byte by byte in a loop
> 5. NTG :)
>
> Regards,
> Talthen
>
>
This changes from an n squared algorithm to an n log n algorithm if you
sort $data and then scan sequentially for consecutive equals. Instead of
100,000,000 operations you will have about 80,000-100,000, depending on
your data and the sorting method. Even faster would be something like:

foreach($data as $v) {
if($test[$v]) {
$err = TRUE;
break;
}
$test[$v] = TRUE;
}
unset{$test}
return $err

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация