News for hackers. Stuff that matters.
Re:Exploring memcmp by cperciva on Wednesday May 13, 2009 @05:37PM (#607708)
memcmp is not the way to do it.

Absolutely. The right way to do it is to use the memmem library call.

A much faster solution would be the same approach rsync takes with its "rolling checksum."

That's one way to improve performance, yes. (But it far predates rsync -- I think it might even predate Tridge.)

In many cases, a "look and skip" algorithm like KMP or BM will outperform a rolling checksum search; but of course if you've got 328MB of data on disk, nothing will make the search faster than the time it takes to read the data into RAM.

Re:Exploring memcmp by brtzsnr on Thursday May 14, 2009 @04:46AM (#608435)
""" A much faster solution would be the same approach rsync takes with its "rolling checksum." """

I know this function is attributed to Bernstein and it's called Bernstein hash [0]. You're describing the Rabin-Karp string matching algorithm [1].

[0] http://fr.wikipedia.org/wiki/Table_de_hachage#Fonction_de_Ha...

[1] http://en.wikipedia.org/wiki/Rabin-Karp_string_search_algori...

Re:Exploring memcmp by jmtulloss on Wednesday May 13, 2009 @08:24PM (#607969)
memmem only returns the first string. I'm looking for a count of all the matches, with their byte offsets in the file.