How does diff compare the differences of 2 files?
Is it implemented with a hash table?
Is it possible that: you "diff" 2 files A and B, and you shuffle the lines of B and diff them again. Will you find the diff results different from time to time?
How does diff compare the differences of 2 files?
Is it implemented with a hash table?
Is it possible that: you "diff" 2 files A and B, and you shuffle the lines of B and diff them again. Will you find the diff results different from time to time?
First off,
Secondly, and more helpfully, if I understand your question correctly you have a couple of options. One of which is to first do the above thing, and use the appropriate command line arguments. The second would be to use grep in conjunction with diff.Code:man diff
I think he is asking about the actual implementation of diff.
Unfortunately I don't know the answer, but it's open source .
Diff compares the actual text content (on text-files, binary files it does a byte-by-byte comparison). It does not use any form of "magic" in the actual comparison - simple string compare [with slight modifications to compensate for flags like "--ignore-white-space" and "--ignore-case"].
Shuffling lines about (assuming the lines are actually different, of course) will definitely always make a difference with diff.
The "magical" part of diff is the bit that figures out where the files are the same again, which I don't actually know how it works - I think it searches forwards until it finds a line that matches, but I'm fairly sure it is a little bit more complex than that.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Look at the source of GNU diff. It starts with a very long comment discussing the algorithm used.
http://www.gnu.org/software/diffutils/diffutils.html
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law