[ https://issues.apache.org/jira/browse/LUCENE-1990?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12904560#action_12904560 ]
Toke Eskildsen commented on LUCENE-1990: ---------------------------------------- I have discovered a bug in Packed32 and Packed64: When the number of bits exceed 2^31, the setters and getters fail. This is due to a missing cast in the calculation of the entry-point in the backing int/long-arrays. In both Packed32 and Packed64 the line {code} final long majorBitPos = index * bitsPerValue; {code} is used in get as well as set. This should be {code} final long majorBitPos = (long)index * bitsPerValue; {code} in all 4 cases. A unit test for this is {code} /* Check if the structures properly handle the case where index * bitsPerValue > Integer.MAX_VALUE */ public void testIntOverflow() { int INDEX = (int) Math.pow(2, 30); int BITS = 4; Packed32 p32 = new Packed32(INDEX, BITS); p32.set(INDEX-1, 1); assertEquals("The value at position " + (INDEX-1) + " should be correct for Packed32", 1, p32.get(INDEX-1)); p32 = null; // To free 512MB Packed64 p64 = new Packed64(INDEX, BITS); p64.set(INDEX-1, 1); assertEquals("The value at position " + (INDEX-1) + " should be correct for Packed64", 1, p64.get(INDEX-1)); } {code} One big problem with the unit-test is that it requires 2^30*4/8 bytes = 512MB of heap. I am guessing that this makes it impossible to run in the standard test-suite. I am unsure as to how I should push this fix through. Should I create a new JIRA issue? Make a patch against trunk? Or maybe a committer could just try the test above and insert the fix in trunk? > Add unsigned packed int impls in oal.util > ----------------------------------------- > > Key: LUCENE-1990 > URL: https://issues.apache.org/jira/browse/LUCENE-1990 > Project: Lucene - Java > Issue Type: Improvement > Components: Index > Affects Versions: Flex Branch > Reporter: Michael McCandless > Priority: Minor > Fix For: 4.0 > > Attachments: generated_performance-te20100226.txt, > LUCENE-1990-te20100122.patch, LUCENE-1990-te20100210.patch, > LUCENE-1990-te20100212.patch, LUCENE-1990-te20100223.patch, > LUCENE-1990-te20100226.patch, LUCENE-1990-te20100226b.patch, > LUCENE-1990-te20100226c.patch, LUCENE-1990-te20100301.patch, > LUCENE-1990.patch, LUCENE-1990.patch, LUCENE-1990.patch, > LUCENE-1990_PerformanceMeasurements20100104.zip, perf-mkm-20100227.txt, > performance-20100301.txt, performance-te20100226.txt > > > There are various places in Lucene that could take advantage of an > efficient packed unsigned int/long impl. EG the terms dict index in > the standard codec in LUCENE-1458 could subsantially reduce it's RAM > usage. FieldCache.StringIndex could as well. And I think "load into > RAM" codecs like the one in TestExternalCodecs could use this too. > I'm picturing something very basic like: > {code} > interface PackedUnsignedLongs { > long get(long index); > void set(long index, long value); > } > {code} > Plus maybe an iterator for getting and maybe also for setting. If it > helps, most of the usages of this inside Lucene will be "write once" > so eg the set could make that an assumption/requirement. > And a factory somewhere: > {code} > PackedUnsignedLongs create(int count, long maxValue); > {code} > I think we should simply autogen the code (we can start from the > autogen code in LUCENE-1410), or, if there is an good existing impl > that has a compatible license that'd be great. > I don't have time near-term to do this... so if anyone has the itch, > please jump! -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org