maedhroz commented on code in PR #2409:
URL: https://github.com/apache/cassandra/pull/2409#discussion_r1227273378


##########
src/java/org/apache/cassandra/index/sai/disk/v1/segment/SegmentBuilder.java:
##########
@@ -71,10 +73,48 @@
     private ByteBuffer minTerm;
     private ByteBuffer maxTerm;
 
+    final AbstractType<?> termComparator;
     long totalBytesAllocated;
     int rowCount = 0;
     int maxSegmentRowId = -1;
 
+    public static class KDTreeSegmentBuilder extends SegmentBuilder
+    {
+        protected final byte[] buffer;
+        private final BKDTreeRamBuffer kdTreeRamBuffer;
+
+        public KDTreeSegmentBuilder(AbstractType<?> termComparator, 
NamedMemoryLimiter limiter)
+        {
+            super(termComparator, limiter);
+
+            int typeSize = TypeUtil.fixedSizeOf(termComparator);
+            this.kdTreeRamBuffer = new BKDTreeRamBuffer(typeSize);
+            this.buffer = new byte[typeSize];
+            this.totalBytesAllocated = this.kdTreeRamBuffer.ramBytesUsed();
+        }
+
+        public boolean isEmpty()
+        {
+            return kdTreeRamBuffer.numRows() == 0;
+        }
+
+        protected long addInternal(ByteBuffer term, int segmentRowId)
+        {
+            TypeUtil.toComparableBytes(term, termComparator, buffer);
+            return kdTreeRamBuffer.addPackedValue(segmentRowId, new 
BytesRef(buffer));
+        }
+
+        @Override
+        protected SegmentMetadata.ComponentMetadataMap 
flushInternal(IndexDescriptor indexDescriptor, IndexContext indexContext) 
throws IOException
+        {
+            NumericIndexWriter writer = new NumericIndexWriter(indexDescriptor,
+                                                               indexContext,
+                                                               
TypeUtil.fixedSizeOf(termComparator),
+                                                               
maxSegmentRowId);
+            return writer.writeAll(kdTreeRamBuffer.asPointValues());
+        }
+    }
+
     public static class RAMStringSegmentBuilder extends SegmentBuilder
     {
         final RAMStringIndexer ramIndexer;

Review Comment:
   nit: Line 247 below needs a `<p>`



-- 
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