jtibshirani commented on code in PR #882:
URL: https://github.com/apache/lucene/pull/882#discussion_r871722263


##########
lucene/core/src/test/org/apache/lucene/util/TestSparseFixedBitSet.java:
##########
@@ -71,4 +71,27 @@ public void testApproximateCardinalityOnDenseSet() {
     }
     assertEquals(numDocs, set.approximateCardinality());
   }
+
+  public void testRamBytesUsed() throws IOException {
+    int size = 1000 + random().nextInt(10000);
+    BitSet original = new SparseFixedBitSet(size);
+    for (int i = 0; i < 3; i++) {
+      original.set(random().nextInt(size));
+    }
+    assertTrue(original.ramBytesUsed() > 0);
+
+    BitSet copy = copyOf(original, size);
+    BitSet otherBitSet = new SparseFixedBitSet(size);
+    int interval = 10 + random().nextInt(100);
+    for (int i = 0; i < size; i += interval) {
+      otherBitSet.set(i);
+    }
+    copy.or(new BitSetIterator(otherBitSet, size));
+    assertTrue(copy.ramBytesUsed() > original.ramBytesUsed());
+
+    copy = copyOf(original, size);
+    copy.or(DocIdSetIterator.all(size));
+    assertTrue(copy.ramBytesUsed() > original.ramBytesUsed());
+    assertTrue(copy.ramBytesUsed() > size / Byte.SIZE);

Review Comment:
   This new test actually caught a bug! As a note, the copy produced with 
`SparseFixedBitSet#or` doesn't always have the exact same memory usage as the 
original, because the "or" method trims some of the oversized bit arrays when 
copying them over.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to