abhishekagarwal87 commented on code in PR #16029:
URL: https://github.com/apache/druid/pull/16029#discussion_r1546147919


##########
processing/src/main/java/org/apache/druid/collections/spatial/ImmutableFloatNode.java:
##########
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.collections.spatial;
+
+import org.apache.druid.collections.bitmap.BitmapFactory;
+import org.apache.druid.collections.bitmap.ImmutableBitmap;
+
+import java.nio.ByteBuffer;
+import java.util.Iterator;
+
+/**
+ * Byte layout:
+ * Header
+ * 0 to 1 : the MSB is a boolean flag for isLeaf, the next 15 bits represent 
the number of children of a node
+ * Body
+ * 2 to 2 + numDims * Float.BYTES : minCoordinates
+ * 2 + numDims * Float.BYTES to 2 + 2 * numDims * Float.BYTES : maxCoordinates
+ * concise set
+ * rest (children) : Every 4 bytes is storing an offset representing the 
position of a child.
+ *
+ * The child offset is an offset from the initialOffset
+ */
+public class ImmutableFloatNode implements ImmutableNode<float[]>
+{
+  public static final int HEADER_NUM_BYTES = 2;
+
+  private final int numDims;
+  private final int initialOffset;
+  private final int offsetFromInitial;
+
+  private final short numChildren;
+  private final boolean isLeaf;
+  private final int childrenOffset;
+
+  private final ByteBuffer data;
+
+  private final BitmapFactory bitmapFactory;
+
+  public ImmutableFloatNode(
+      int numDims,
+      int initialOffset,
+      int offsetFromInitial,
+      ByteBuffer data,
+      BitmapFactory bitmapFactory
+  )
+  {
+    this.bitmapFactory = bitmapFactory;
+    this.numDims = numDims;
+    this.initialOffset = initialOffset;
+    this.offsetFromInitial = offsetFromInitial;
+    short header = data.getShort(initialOffset + offsetFromInitial);
+    this.isLeaf = (header & 0x8000) != 0;
+    this.numChildren = (short) (header & 0x7FFF);
+    final int sizePosition = initialOffset + offsetFromInitial + 
HEADER_NUM_BYTES + 2 * numDims * Float.BYTES;
+    int bitmapSize = data.getInt(sizePosition);
+    this.childrenOffset = initialOffset
+                          + offsetFromInitial
+                          + HEADER_NUM_BYTES
+                          + 2 * numDims * Float.BYTES
+                          + Integer.BYTES
+                          + bitmapSize;
+
+    this.data = data;

Review Comment:
   ```suggestion
       this(numDims, initialOffset, offsetFromInitial, numChildren, leaf, data, 
bitmapFactory)
   ```



##########
processing/src/main/java/org/apache/druid/collections/spatial/ImmutableFloatNode.java:
##########
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.collections.spatial;
+
+import org.apache.druid.collections.bitmap.BitmapFactory;
+import org.apache.druid.collections.bitmap.ImmutableBitmap;
+
+import java.nio.ByteBuffer;
+import java.util.Iterator;
+
+/**
+ * Byte layout:
+ * Header
+ * 0 to 1 : the MSB is a boolean flag for isLeaf, the next 15 bits represent 
the number of children of a node
+ * Body
+ * 2 to 2 + numDims * Float.BYTES : minCoordinates
+ * 2 + numDims * Float.BYTES to 2 + 2 * numDims * Float.BYTES : maxCoordinates
+ * concise set
+ * rest (children) : Every 4 bytes is storing an offset representing the 
position of a child.
+ *
+ * The child offset is an offset from the initialOffset
+ */
+public class ImmutableFloatNode implements ImmutableNode<float[]>
+{
+  public static final int HEADER_NUM_BYTES = 2;
+
+  private final int numDims;
+  private final int initialOffset;
+  private final int offsetFromInitial;
+
+  private final short numChildren;
+  private final boolean isLeaf;
+  private final int childrenOffset;
+
+  private final ByteBuffer data;
+
+  private final BitmapFactory bitmapFactory;
+
+  public ImmutableFloatNode(
+      int numDims,
+      int initialOffset,
+      int offsetFromInitial,
+      ByteBuffer data,
+      BitmapFactory bitmapFactory
+  )
+  {
+    this.bitmapFactory = bitmapFactory;
+    this.numDims = numDims;
+    this.initialOffset = initialOffset;
+    this.offsetFromInitial = offsetFromInitial;
+    short header = data.getShort(initialOffset + offsetFromInitial);
+    this.isLeaf = (header & 0x8000) != 0;
+    this.numChildren = (short) (header & 0x7FFF);
+    final int sizePosition = initialOffset + offsetFromInitial + 
HEADER_NUM_BYTES + 2 * numDims * Float.BYTES;
+    int bitmapSize = data.getInt(sizePosition);
+    this.childrenOffset = initialOffset
+                          + offsetFromInitial
+                          + HEADER_NUM_BYTES
+                          + 2 * numDims * Float.BYTES
+                          + Integer.BYTES
+                          + bitmapSize;

Review Comment:
   ```suggestion
       this.childrenOffset = sizePosition
                             + Integer.BYTES
                             + bitmapSize;
   ```



##########
processing/src/main/java/org/apache/druid/collections/spatial/ImmutableFloatNode.java:
##########
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.collections.spatial;
+
+import org.apache.druid.collections.bitmap.BitmapFactory;
+import org.apache.druid.collections.bitmap.ImmutableBitmap;
+
+import java.nio.ByteBuffer;
+import java.util.Iterator;
+
+/**
+ * Byte layout:

Review Comment:
   What is the child here and what is the dim? 



##########
processing/src/test/java/org/apache/druid/collections/spatial/SpatialUtils.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.collections.spatial;
+
+import java.util.Random;
+import java.util.concurrent.ThreadLocalRandom;
+
+public class SpatialUtils
+{
+  private static Random random = ThreadLocalRandom.current();
+
+  public static float[][] generateGeoCoordinatesAroundCircle(

Review Comment:
   since its only used in test, the method should be moved to test code



-- 
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: commits-unsubscr...@druid.apache.org

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


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

Reply via email to