leerho commented on code in PR #800:
URL: https://github.com/apache/datasketches-java/pull/800#discussion_r4592227220


##########
src/main/java/org/apache/datasketches/kll/KllHeapItemsSketch.java:
##########
@@ -119,12 +119,12 @@ final class KllHeapItemsSketch<T> extends 
KllItemsSketch<T> {
     n = segVal.n;
     minK = segVal.minK;
     isLevelZeroSorted = segVal.level0SortedFlag;
-    itemsArr = new Object[levelsArr[segVal.numLevels]]; //updatable size
     final SketchStructure segStruct = segVal.sketchStructure;
+    //an empty image allocates no item storage; it is allocated on first use
+    itemsArr = (segStruct == COMPACT_EMPTY) ? null : new 
Object[levelsArr[segVal.numLevels]]; //updatable size

Review Comment:
   Good catch, thanks. It wasn't intended. Fixed in 02a794742:
   
   - **Items sketch:** heapify now allocates the items array only in the 
single-item and full branches, so an updatable image is rejected without 
allocating first.
   - **Doubles, Floats, Longs:** an updatable image of an empty sketch (no 
items, base level only) now heapifies without item storage, the same as a 
compact empty image. The storage is allocated on first use. Updatable images 
that hold items are unchanged.
   
   New tests in `KllLazyAllocationTest` cover both, and check that the 
updatable empty image re-serializes byte for byte.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to