LUCENE-1990: fix Mutable case where out-of-order writes could incorrectly overwrite adjacent values

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@931327 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2010-04-06 20:58:22 +00:00
parent 29ff915048
commit ba9876c4f5
3 changed files with 25 additions and 7 deletions

View File

@ -88,9 +88,14 @@ class Packed32 extends PackedInts.ReaderImpl implements PackedInts.Mutable {
currentMasks[base ] =~((elementPosMask
<< currentShifts[base + 1])
>>> currentShifts[base]);
currentMasks[base+1] = ~(elementPosMask
<< currentShifts[base + 2]);
currentMasks[base+2] = currentShifts[base + 2] == 0 ? 0 : ~0;
if (bitPos <= BLOCK_SIZE - elementBits) { // Second block not used
currentMasks[base+1] = ~0; // Keep all bits
currentMasks[base+2] = 0; // Or with 0
} else {
currentMasks[base+1] = ~(elementPosMask
<< currentShifts[base + 2]);
currentMasks[base+2] = currentShifts[base + 2] == 0 ? 0 : ~0;
}
}
}
}

View File

@ -89,9 +89,14 @@ class Packed64 extends PackedInts.ReaderImpl implements PackedInts.Mutable {
currentMasks[base ] =~((elementPosMask
<< currentShifts[base + 1])
>>> currentShifts[base]);
currentMasks[base+1] = ~(elementPosMask
<< currentShifts[base + 2]);
currentMasks[base+2] = currentShifts[base + 2] == 0 ? 0 : ~0;
if (bitPos <= BLOCK_SIZE - elementBits) { // Second block not used
currentMasks[base+1] = ~0; // Keep all bits
currentMasks[base+2] = 0; // Or with 0
} else {
currentMasks[base+1] = ~(elementPosMask
<< currentShifts[base + 2]);
currentMasks[base+2] = currentShifts[base + 2] == 0 ? 0 : ~0;
}
}
}
}

View File

@ -216,10 +216,18 @@ public class TestPackedInts extends LuceneTestCase {
out.close();
IndexInput in = dir.openInput("out");
PackedInts.Reader r = PackedInts.getReader(in);
PackedInts.getReader(in);
assertEquals(end, in.getFilePointer());
in.close();
dir.close();
}
public void testSecondaryBlockChange() throws IOException {
PackedInts.Mutable mutable = new Packed64(26, 5);
mutable.set(24, 31);
assertEquals("The value #24 should be correct", 31, mutable.get(24));
mutable.set(4, 16);
assertEquals("The value #24 should remain unchanged", 31, mutable.get(24));
}
}