Bugs: Browse | Download .csv
The functions are incorrect. Bitset.diff a b can calculate the wrong answer when the underlying string for a is longer than the underlying string for b. Here is the code: 1. let diff a b = 2. let maxlen = max a.len b.len in 3. let buf = bcreate maxlen in 4. bblit a.data 0 buf 0 a.len; 5. let sl = min a.len b.len in 6. let abuf = a.data 7. and bbuf = b.data in 8. for i = 0 to sl-1 do 9. bset buf i ((bget abuf i) land (lnot (bget bbuf i))) 10. done; 11. { data = buf; len = maxlen } If b is longer than a, the result, buf, gets created on line 3 at the same size as b. The contents of buf at this point are garbage, bcreate does not clear them. The bblit on line 4 copies a into buf, leaving some garbage at the end. The for loop on line 8 touches only up to the length of a, so there is still garbage at the end. A second issue is that differentiate is defined in terms of diff. This is undesirable because it ends up bcreating a new buffer and throwing away an old buffer; I expect from the type of differentiate that it reuses its buffer. A fix is to use this for differentiate: let differentiate a b = let sl = min a.len b.len in let abuf = a.data and bbuf = b.data in for i = 0 to sl-1 do bset abuf i ((bget abuf i) land (lnot (bget bbuf i))) done Then define (diff a b) by copying a and using differentiate on the result.
Date: 2009-06-19 16:09 Sender: Trevor Jim Hard to construct a test case because the garbage is nondeterministic. E.g., it's possible that it works correctly depending on what random garbage is in the buffer.
Date: 2009-06-19 07:52 Sender: David Teller Diff should now be fixed. Differentiate will come next. Do you have a short testcase we could add to the testsuite?