This is an automated email from the ASF dual-hosted git repository.

bchapuis pushed a commit to branch calcite
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git

commit 1b8afdfdf106c02f011d53844b5606bea5559b0a
Author: Bertil Chapuis <[email protected]>
AuthorDate: Thu Jun 22 21:24:35 2023 +0200

    Add array data types
---
 .../baremaps/benchmarks/DataMapBenchmark.java      |  2 +-
 .../baremaps/benchmarks/MemoryBenchmark.java       | 14 +++++------
 .../java/org/apache/baremaps/calcite/Calcite.java  |  4 +---
 .../baremaps/collection/algorithm/Hilbert.java     |  5 ++--
 .../baremaps/collection/store/DataColumnType.java  | 23 +++++++++++++-----
 ...ListDataType.java => BooleanArrayDataType.java} | 27 +++++++++++-----------
 ...tListDataType.java => BooleanListDataType.java} | 25 ++++++++++----------
 .../collection/type/ByteArrayDataType.java         |  2 +-
 .../baremaps/collection/type/ByteListDataType.java |  2 +-
 .../collection/type/DoubleArrayDataType.java       | 14 +++++------
 .../collection/type/DoubleListDataType.java        | 15 ++++++------
 ...atListDataType.java => FloatArrayDataType.java} | 23 +++++++++---------
 .../collection/type/FloatListDataType.java         | 11 +++++----
 ...ListDataType.java => IntegerArrayDataType.java} | 25 ++++++++++----------
 .../collection/type/IntegerListDataType.java       | 13 ++++++-----
 .../baremaps/collection/type/ListDataType.java     |  4 ++--
 ...ongListDataType.java => LongArrayDataType.java} | 25 ++++++++++----------
 .../baremaps/collection/type/LongListDataType.java | 13 ++++++-----
 .../baremaps/collection/type/MapDataType.java      |  4 ++--
 .../baremaps/collection/type/PairDataType.java     |  4 +---
 .../baremaps/collection/type/RowDataType.java      |  6 ++---
 ...rtListDataType.java => ShortArrayDataType.java} | 27 +++++++++++-----------
 .../collection/type/ShortListDataType.java         | 15 ++++++------
 .../baremaps/collection/type/StringDataType.java   |  6 ++---
 .../baremaps/collection/type/DataTypeProvider.java | 16 +++++++++++++
 25 files changed, 172 insertions(+), 153 deletions(-)

diff --git 
a/baremaps-benchmark/src/main/java/org/apache/baremaps/benchmarks/DataMapBenchmark.java
 
b/baremaps-benchmark/src/main/java/org/apache/baremaps/benchmarks/DataMapBenchmark.java
index 1cbcbe02..32d8c660 100644
--- 
a/baremaps-benchmark/src/main/java/org/apache/baremaps/benchmarks/DataMapBenchmark.java
+++ 
b/baremaps-benchmark/src/main/java/org/apache/baremaps/benchmarks/DataMapBenchmark.java
@@ -29,7 +29,7 @@ import org.openjdk.jmh.runner.options.OptionsBuilder;
 @Fork(1)
 public class DataMapBenchmark {
 
-  private static final long N = 1 << 25;
+  private static final long N = 1 << 22;
 
   private static void benchmark(DataMap<Long> store, long n) {
     for (long i = 0; i < n; i++) {
diff --git 
a/baremaps-benchmark/src/main/java/org/apache/baremaps/benchmarks/MemoryBenchmark.java
 
b/baremaps-benchmark/src/main/java/org/apache/baremaps/benchmarks/MemoryBenchmark.java
index 85bb831c..b73de106 100644
--- 
a/baremaps-benchmark/src/main/java/org/apache/baremaps/benchmarks/MemoryBenchmark.java
+++ 
b/baremaps-benchmark/src/main/java/org/apache/baremaps/benchmarks/MemoryBenchmark.java
@@ -39,11 +39,12 @@ import org.openjdk.jmh.runner.RunnerException;
 import org.openjdk.jmh.runner.options.OptionsBuilder;
 
 @State(Scope.Benchmark)
-@OutputTimeUnit(TimeUnit.MILLISECONDS)
 @Fork(1)
+@Warmup(iterations = 1)
+@Measurement(iterations = 1)
 public class MemoryBenchmark {
 
-  private static final long N = 1 << 25;
+  private static final long N = 1 << 28;
 
   private void benchmark(DataMap<Long> store, long n) {
     for (long i = 0; i < n; i++) {
@@ -59,24 +60,21 @@ public class MemoryBenchmark {
 
   @Benchmark
   @BenchmarkMode(Mode.SingleShotTime)
-  @Warmup(iterations = 2)
-  @Measurement(iterations = 5)
+  @OutputTimeUnit(TimeUnit.MILLISECONDS)
   public void onHeap() {
     benchmark(new MemoryAlignedDataMap<>(new LongDataType(), new 
OnHeapMemory()), N);
   }
 
   @Benchmark
   @BenchmarkMode(Mode.SingleShotTime)
-  @Warmup(iterations = 2)
-  @Measurement(iterations = 5)
+  @OutputTimeUnit(TimeUnit.MILLISECONDS)
   public void offHeap() {
     benchmark(new MemoryAlignedDataMap<>(new LongDataType(), new 
OffHeapMemory()), N);
   }
 
   @Benchmark
   @BenchmarkMode(Mode.SingleShotTime)
-  @Warmup(iterations = 2)
-  @Measurement(iterations = 5)
+  @OutputTimeUnit(TimeUnit.MILLISECONDS)
   public void onDisk() throws IOException {
     Path file = Files.createTempFile(Paths.get("."), "baremaps_", ".tmp");
     benchmark(new MemoryAlignedDataMap<>(new LongDataType(), new 
MemoryMappedFile(file)),
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/calcite/Calcite.java 
b/baremaps-core/src/main/java/org/apache/baremaps/calcite/Calcite.java
index 452563d6..9ba44757 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/calcite/Calcite.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/calcite/Calcite.java
@@ -85,8 +85,7 @@ public class Calcite {
     info.setProperty("lex", "MYSQL");
 
     Connection connection = DriverManager.getConnection("jdbc:calcite:", info);
-    CalciteConnection calciteConnection =
-        connection.unwrap(CalciteConnection.class);
+    CalciteConnection calciteConnection = 
connection.unwrap(CalciteConnection.class);
 
     SchemaPlus rootSchema = calciteConnection.getRootSchema();
 
@@ -113,7 +112,6 @@ public class Calcite {
       System.out.println(
           resultSet.getString(1) + ", " + resultSet.getObject(2) + ", " + 
resultSet.getInt(3));
     }
-
     resultSet.close();
   }
 
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/algorithm/Hilbert.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/algorithm/Hilbert.java
index c7c72b7c..9cad23f7 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/algorithm/Hilbert.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/algorithm/Hilbert.java
@@ -17,9 +17,8 @@ import org.locationtech.jts.geom.Envelope;
 import org.locationtech.jts.geom.Geometry;
 
 /**
- * A utility class for computing the Hilbert curve index of geometries.
- *
- * Based on the implementation of the Hilbert curve in the flatgeobuf project 
(BSD 2-Clause).
+ * A utility class for computing the Hilbert curve index of geometries. Based 
on the implementation
+ * of the Hilbert curve in the flatgeobuf project (BSD 2-Clause).
  */
 public class Hilbert {
 
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/store/DataColumnType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/store/DataColumnType.java
index 301457cc..a9a313c8 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/store/DataColumnType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/store/DataColumnType.java
@@ -15,12 +15,23 @@ package org.apache.baremaps.collection.store;
 import org.locationtech.jts.geom.*;
 
 public enum DataColumnType {
-  BOOLEAN(Boolean.class), BYTE(Byte.class), SHORT(Short.class), 
INTEGER(Integer.class), LONG(
-      Long.class), FLOAT(Float.class), DOUBLE(Double.class), STRING(
-          String.class), BYTES(byte[].class), GEOMETRY(Geometry.class), POINT(
-              Point.class), LINESTRING(LineString.class), 
POLYGON(Polygon.class), MULTIPOINT(
-                  MultiPoint.class), MULTILINESTRING(MultiLineString.class), 
MULTIPOLYGON(
-                      MultiPolygon.class), 
GEOMETRYCOLLECTION(GeometryCollection.class);
+  BOOLEAN(Boolean.class),
+  BYTE(Byte.class),
+  SHORT(Short.class),
+  INTEGER(Integer.class),
+  LONG(Long.class),
+  FLOAT(Float.class),
+  DOUBLE(Double.class),
+  STRING(String.class),
+  BYTES(byte[].class),
+  GEOMETRY(Geometry.class),
+  POINT(Point.class),
+  LINESTRING(LineString.class),
+  POLYGON(Polygon.class),
+  MULTIPOINT(MultiPoint.class),
+  MULTILINESTRING(MultiLineString.class),
+  MULTIPOLYGON(MultiPolygon.class),
+  GEOMETRYCOLLECTION(GeometryCollection.class);
 
   private Class<?> type;
 
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/FloatListDataType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/BooleanArrayDataType.java
similarity index 65%
copy from 
baremaps-core/src/main/java/org/apache/baremaps/collection/type/FloatListDataType.java
copy to 
baremaps-core/src/main/java/org/apache/baremaps/collection/type/BooleanArrayDataType.java
index f0f9ff4b..002f8030 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/FloatListDataType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/BooleanArrayDataType.java
@@ -15,16 +15,14 @@ package org.apache.baremaps.collection.type;
 
 
 import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
 
 /** A {@link DataType} for reading and writing lists of floats in {@link 
ByteBuffer}s. */
-public class FloatListDataType implements DataType<List<Float>> {
+public class BooleanArrayDataType implements DataType<boolean[]> {
 
   /** {@inheritDoc} */
   @Override
-  public int size(final List<Float> values) {
-    return Integer.BYTES + values.size() * Float.BYTES;
+  public int size(final boolean[] values) {
+    return Integer.BYTES + values.length * Byte.BYTES;
   }
 
   /** {@inheritDoc} */
@@ -35,23 +33,24 @@ public class FloatListDataType implements 
DataType<List<Float>> {
 
   /** {@inheritDoc} */
   @Override
-  public void write(final ByteBuffer buffer, final int position, final 
List<Float> values) {
+  public void write(final ByteBuffer buffer, final int position, final 
boolean[] values) {
     buffer.putInt(position, size(values));
     var p = position + Integer.BYTES;
-    for (Float value : values) {
-      buffer.putFloat(p, value);
-      p += Float.BYTES;
+    for (boolean value : values) {
+        buffer.put(p, (byte) (value ? 1 : 0));
+        p += Byte.BYTES;
     }
   }
 
   /** {@inheritDoc} */
   @Override
-  public List<Float> read(final ByteBuffer buffer, final int position) {
+  public boolean[] read(final ByteBuffer buffer, final int position) {
     int size = buffer.getInt(position);
-    List<Float> list = new ArrayList<>(size);
-    for (var p = position + Integer.BYTES; p < position + size; p += 
Float.BYTES) {
-      list.add(buffer.getFloat(p));
+    int length = (size - Integer.BYTES) / Byte.BYTES;
+    boolean[] values = new boolean[length];
+    for (int index = 0; index < length; index++) {
+        values[index] = buffer.get(position + Integer.BYTES + index * 
Byte.BYTES) == 1;
     }
-    return list;
+    return values;
   }
 }
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/FloatListDataType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/BooleanListDataType.java
similarity index 65%
copy from 
baremaps-core/src/main/java/org/apache/baremaps/collection/type/FloatListDataType.java
copy to 
baremaps-core/src/main/java/org/apache/baremaps/collection/type/BooleanListDataType.java
index f0f9ff4b..2a31bf5c 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/FloatListDataType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/BooleanListDataType.java
@@ -19,12 +19,12 @@ import java.util.ArrayList;
 import java.util.List;
 
 /** A {@link DataType} for reading and writing lists of floats in {@link 
ByteBuffer}s. */
-public class FloatListDataType implements DataType<List<Float>> {
+public class BooleanListDataType implements DataType<List<Boolean>> {
 
   /** {@inheritDoc} */
   @Override
-  public int size(final List<Float> values) {
-    return Integer.BYTES + values.size() * Float.BYTES;
+  public int size(final List<Boolean> values) {
+    return Integer.BYTES + values.size() * Byte.BYTES;
   }
 
   /** {@inheritDoc} */
@@ -35,23 +35,24 @@ public class FloatListDataType implements 
DataType<List<Float>> {
 
   /** {@inheritDoc} */
   @Override
-  public void write(final ByteBuffer buffer, final int position, final 
List<Float> values) {
+  public void write(final ByteBuffer buffer, final int position, final 
List<Boolean> values) {
     buffer.putInt(position, size(values));
     var p = position + Integer.BYTES;
-    for (Float value : values) {
-      buffer.putFloat(p, value);
-      p += Float.BYTES;
+    for (boolean value : values) {
+        buffer.put(p, (byte) (value ? 1 : 0));
+        p += Byte.BYTES;
     }
   }
 
   /** {@inheritDoc} */
   @Override
-  public List<Float> read(final ByteBuffer buffer, final int position) {
+  public List<Boolean> read(final ByteBuffer buffer, final int position) {
     int size = buffer.getInt(position);
-    List<Float> list = new ArrayList<>(size);
-    for (var p = position + Integer.BYTES; p < position + size; p += 
Float.BYTES) {
-      list.add(buffer.getFloat(p));
+    int length = (size - Integer.BYTES) / Byte.BYTES;
+    var values = new ArrayList<Boolean>(length);
+    for (int index = 0; index < length; index++) {
+        values.add(buffer.get(position + Integer.BYTES + index * Byte.BYTES) 
== 1);
     }
-    return list;
+    return values;
   }
 }
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ByteArrayDataType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ByteArrayDataType.java
index 98666d44..b9815cde 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ByteArrayDataType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ByteArrayDataType.java
@@ -51,7 +51,7 @@ public class ByteArrayDataType implements DataType<byte[]> {
   @Override
   public byte[] read(final ByteBuffer buffer, final int position) {
     int size = buffer.getInt(position);
-    var values = new byte[Math.max(size - Integer.BYTES, 0)];
+    byte[] values = new byte[Math.max(size - Integer.BYTES, 0)];
     buffer.get(position + Integer.BYTES, values);
     return values;
   }
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ByteListDataType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ByteListDataType.java
index 58834b22..debe5e83 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ByteListDataType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ByteListDataType.java
@@ -55,7 +55,7 @@ public class ByteListDataType implements DataType<List<Byte>> 
{
   @Override
   public List<Byte> read(final ByteBuffer buffer, final int position) {
     int size = buffer.getInt(position);
-    var bytes = new byte[Math.max(size - Integer.BYTES, 0)];
+    byte[] bytes = new byte[Math.max(size - Integer.BYTES, 0)];
     buffer.get(position + Integer.BYTES, bytes);
     return Bytes.asList(bytes);
   }
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/DoubleArrayDataType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/DoubleArrayDataType.java
index 57756c8c..bfd8b670 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/DoubleArrayDataType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/DoubleArrayDataType.java
@@ -45,14 +45,12 @@ public class DoubleArrayDataType implements 
DataType<double[]> {
   /** {@inheritDoc} */
   @Override
   public double[] read(final ByteBuffer buffer, final int position) {
-    var size = buffer.getInt(position);
-    var length = (size - Integer.BYTES) / Double.BYTES;
-    var list = new double[length];
-    var index = 0;
-    for (var p = position + Integer.BYTES; p < position + size; p += 
Double.BYTES) {
-      list[index] = buffer.getDouble(p);
-      index++;
+    int size = buffer.getInt(position);
+    int length = (size - Integer.BYTES) / Double.BYTES;
+    double[] values = new double[length];
+    for (int index = 0; index < length; index++) {
+      values[index] = buffer.getDouble(position + Integer.BYTES + index * 
Double.BYTES);
     }
-    return list;
+    return values;
   }
 }
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/DoubleListDataType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/DoubleListDataType.java
index 3c42f26f..4a0d43ec 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/DoubleListDataType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/DoubleListDataType.java
@@ -37,8 +37,8 @@ public class DoubleListDataType implements 
DataType<List<Double>> {
   @Override
   public void write(final ByteBuffer buffer, final int position, final 
List<Double> values) {
     buffer.putInt(position, size(values));
-    var p = position + Integer.BYTES;
-    for (Double value : values) {
+    int p = position + Integer.BYTES;
+    for (double value : values) {
       buffer.putDouble(p, value);
       p += Double.BYTES;
     }
@@ -47,11 +47,12 @@ public class DoubleListDataType implements 
DataType<List<Double>> {
   /** {@inheritDoc} */
   @Override
   public List<Double> read(final ByteBuffer buffer, final int position) {
-    var size = buffer.getInt(position);
-    var list = new ArrayList<Double>(size);
-    for (var p = position + Integer.BYTES; p < position + size; p += 
Double.BYTES) {
-      list.add(buffer.getDouble(p));
+    int size = buffer.getInt(position);
+    int length = (size - Integer.BYTES) / Double.BYTES;
+    var values = new ArrayList<Double>(length);
+    for (int index = 0; index < length; index++) {
+      values.add(buffer.getDouble(position + Integer.BYTES + index * 
Double.BYTES));
     }
-    return list;
+    return values;
   }
 }
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/FloatListDataType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/FloatArrayDataType.java
similarity index 69%
copy from 
baremaps-core/src/main/java/org/apache/baremaps/collection/type/FloatListDataType.java
copy to 
baremaps-core/src/main/java/org/apache/baremaps/collection/type/FloatArrayDataType.java
index f0f9ff4b..3458c88c 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/FloatListDataType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/FloatArrayDataType.java
@@ -15,16 +15,14 @@ package org.apache.baremaps.collection.type;
 
 
 import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
 
 /** A {@link DataType} for reading and writing lists of floats in {@link 
ByteBuffer}s. */
-public class FloatListDataType implements DataType<List<Float>> {
+public class FloatArrayDataType implements DataType<float[]> {
 
   /** {@inheritDoc} */
   @Override
-  public int size(final List<Float> values) {
-    return Integer.BYTES + values.size() * Float.BYTES;
+  public int size(final float[] values) {
+    return Integer.BYTES + values.length * Float.BYTES;
   }
 
   /** {@inheritDoc} */
@@ -35,10 +33,10 @@ public class FloatListDataType implements 
DataType<List<Float>> {
 
   /** {@inheritDoc} */
   @Override
-  public void write(final ByteBuffer buffer, final int position, final 
List<Float> values) {
+  public void write(final ByteBuffer buffer, final int position, final float[] 
values) {
     buffer.putInt(position, size(values));
     var p = position + Integer.BYTES;
-    for (Float value : values) {
+    for (float value : values) {
       buffer.putFloat(p, value);
       p += Float.BYTES;
     }
@@ -46,12 +44,13 @@ public class FloatListDataType implements 
DataType<List<Float>> {
 
   /** {@inheritDoc} */
   @Override
-  public List<Float> read(final ByteBuffer buffer, final int position) {
+  public float[] read(final ByteBuffer buffer, final int position) {
     int size = buffer.getInt(position);
-    List<Float> list = new ArrayList<>(size);
-    for (var p = position + Integer.BYTES; p < position + size; p += 
Float.BYTES) {
-      list.add(buffer.getFloat(p));
+    int length = (size - Integer.BYTES) / Float.BYTES;
+    float[] values = new float[length];
+    for (int index = 0; index < length; index++) {
+      values[index] = buffer.getFloat(position + Integer.BYTES + index * 
Float.BYTES);
     }
-    return list;
+    return values;
   }
 }
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/FloatListDataType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/FloatListDataType.java
index f0f9ff4b..231e4cd9 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/FloatListDataType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/FloatListDataType.java
@@ -38,7 +38,7 @@ public class FloatListDataType implements 
DataType<List<Float>> {
   public void write(final ByteBuffer buffer, final int position, final 
List<Float> values) {
     buffer.putInt(position, size(values));
     var p = position + Integer.BYTES;
-    for (Float value : values) {
+    for (float value : values) {
       buffer.putFloat(p, value);
       p += Float.BYTES;
     }
@@ -48,10 +48,11 @@ public class FloatListDataType implements 
DataType<List<Float>> {
   @Override
   public List<Float> read(final ByteBuffer buffer, final int position) {
     int size = buffer.getInt(position);
-    List<Float> list = new ArrayList<>(size);
-    for (var p = position + Integer.BYTES; p < position + size; p += 
Float.BYTES) {
-      list.add(buffer.getFloat(p));
+    int length = (size - Integer.BYTES) / Float.BYTES;
+    var values = new ArrayList<Float>(length);
+    for (int index = 0; index < length; index++) {
+      values.add(buffer.getFloat(position + Integer.BYTES + index * 
Float.BYTES));
     }
-    return list;
+    return values;
   }
 }
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/IntegerListDataType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/IntegerArrayDataType.java
similarity index 66%
copy from 
baremaps-core/src/main/java/org/apache/baremaps/collection/type/IntegerListDataType.java
copy to 
baremaps-core/src/main/java/org/apache/baremaps/collection/type/IntegerArrayDataType.java
index 1ae2174e..57624b2e 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/IntegerListDataType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/IntegerArrayDataType.java
@@ -15,16 +15,14 @@ package org.apache.baremaps.collection.type;
 
 
 import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
 
 /** A {@link DataType} for reading and writing lists of integers in {@link 
ByteBuffer}s. */
-public class IntegerListDataType implements DataType<List<Integer>> {
+public class IntegerArrayDataType implements DataType<int[]> {
 
   /** {@inheritDoc} */
   @Override
-  public int size(final List<Integer> values) {
-    return Integer.BYTES + values.size() * Integer.BYTES;
+  public int size(final int[] values) {
+    return Integer.BYTES + values.length * Integer.BYTES;
   }
 
   @Override
@@ -34,10 +32,10 @@ public class IntegerListDataType implements 
DataType<List<Integer>> {
 
   /** {@inheritDoc} */
   @Override
-  public void write(final ByteBuffer buffer, final int position, final 
List<Integer> values) {
+  public void write(final ByteBuffer buffer, final int position, final int[] 
values) {
     buffer.putInt(position, size(values));
     var p = position + Integer.BYTES;
-    for (Integer value : values) {
+    for (int value : values) {
       buffer.putInt(p, value);
       p += Integer.BYTES;
     }
@@ -45,12 +43,13 @@ public class IntegerListDataType implements 
DataType<List<Integer>> {
 
   /** {@inheritDoc} */
   @Override
-  public List<Integer> read(final ByteBuffer buffer, final int position) {
-    var size = size(buffer, position);
-    var list = new ArrayList<Integer>();
-    for (var p = position + Integer.BYTES; p < position + size; p += 
Integer.BYTES) {
-      list.add(buffer.getInt(p));
+  public int[] read(final ByteBuffer buffer, final int position) {
+    int size = buffer.getInt(position);
+    int length = (size - Integer.BYTES) / Integer.BYTES;
+    int[] values = new int[length];
+    for (int index = 0; index < length; index++) {
+      values[index] = buffer.getInt(position + Integer.BYTES + index * 
Integer.BYTES);
     }
-    return list;
+    return values;
   }
 }
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/IntegerListDataType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/IntegerListDataType.java
index 1ae2174e..09436408 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/IntegerListDataType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/IntegerListDataType.java
@@ -37,7 +37,7 @@ public class IntegerListDataType implements 
DataType<List<Integer>> {
   public void write(final ByteBuffer buffer, final int position, final 
List<Integer> values) {
     buffer.putInt(position, size(values));
     var p = position + Integer.BYTES;
-    for (Integer value : values) {
+    for (int value : values) {
       buffer.putInt(p, value);
       p += Integer.BYTES;
     }
@@ -46,11 +46,12 @@ public class IntegerListDataType implements 
DataType<List<Integer>> {
   /** {@inheritDoc} */
   @Override
   public List<Integer> read(final ByteBuffer buffer, final int position) {
-    var size = size(buffer, position);
-    var list = new ArrayList<Integer>();
-    for (var p = position + Integer.BYTES; p < position + size; p += 
Integer.BYTES) {
-      list.add(buffer.getInt(p));
+    int size = buffer.getInt(position);
+    int length = (size - Integer.BYTES) / Integer.BYTES;
+    var values = new ArrayList<Integer>(length);
+    for (int index = 0; index < length; index++) {
+      values.add(buffer.getInt(position + Integer.BYTES + index * 
Integer.BYTES));
     }
-    return list;
+    return values;
   }
 }
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ListDataType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ListDataType.java
index fc99520c..a8bf99dc 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ListDataType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ListDataType.java
@@ -53,7 +53,7 @@ public class ListDataType<T> implements DataType<List<T>> {
   @Override
   public void write(final ByteBuffer buffer, final int position, final List<T> 
values) {
     buffer.putInt(position, size(values));
-    var p = position + Integer.BYTES;
+    int p = position + Integer.BYTES;
     for (T value : values) {
       dataType.write(buffer, p, value);
       p += dataType.size(value);
@@ -63,7 +63,7 @@ public class ListDataType<T> implements DataType<List<T>> {
   /** {@inheritDoc} */
   @Override
   public List<T> read(final ByteBuffer buffer, final int position) {
-    var size = buffer.getInt(position);
+    int size = buffer.getInt(position);
     var list = new ArrayList<T>(size);
     for (var p = position + Integer.BYTES; p < position + size; p += 
dataType.size(buffer, p)) {
       list.add(dataType.read(buffer, p));
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/LongListDataType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/LongArrayDataType.java
similarity index 67%
copy from 
baremaps-core/src/main/java/org/apache/baremaps/collection/type/LongListDataType.java
copy to 
baremaps-core/src/main/java/org/apache/baremaps/collection/type/LongArrayDataType.java
index 2e1e0daa..f49efb0a 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/LongListDataType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/LongArrayDataType.java
@@ -15,16 +15,14 @@ package org.apache.baremaps.collection.type;
 
 
 import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
 
 /** A {@link DataType} for reading and writing lists of longs in {@link 
ByteBuffer}s. */
-public class LongListDataType implements DataType<List<Long>> {
+public class LongArrayDataType implements DataType<long[]> {
 
   /** {@inheritDoc} */
   @Override
-  public int size(final List<Long> values) {
-    return Integer.BYTES + values.size() * Long.BYTES;
+  public int size(final long[] values) {
+    return Integer.BYTES + values.length * Long.BYTES;
   }
 
   /** {@inheritDoc} */
@@ -35,10 +33,10 @@ public class LongListDataType implements 
DataType<List<Long>> {
 
   /** {@inheritDoc} */
   @Override
-  public void write(final ByteBuffer buffer, final int position, final 
List<Long> values) {
+  public void write(final ByteBuffer buffer, final int position, final long[] 
values) {
     buffer.putInt(position, size(values));
     var p = position + Integer.BYTES;
-    for (Long value : values) {
+    for (long value : values) {
       buffer.putLong(p, value);
       p += Long.BYTES;
     }
@@ -46,12 +44,13 @@ public class LongListDataType implements 
DataType<List<Long>> {
 
   /** {@inheritDoc} */
   @Override
-  public List<Long> read(final ByteBuffer buffer, final int position) {
-    var size = buffer.getInt(position);
-    var list = new ArrayList<Long>(size);
-    for (var p = position + Integer.BYTES; p < position + size; p += 
Long.BYTES) {
-      list.add(buffer.getLong(p));
+  public long[] read(final ByteBuffer buffer, final int position) {
+    int size = buffer.getInt(position);
+    int length = (size - Integer.BYTES) / Long.BYTES;
+    long[] values = new long[length];
+    for (int index = 0; index < length; index++) {
+      values[index] = buffer.getLong(position + Integer.BYTES + index * 
Long.BYTES);
     }
-    return list;
+    return values;
   }
 }
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/LongListDataType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/LongListDataType.java
index 2e1e0daa..4a5c1541 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/LongListDataType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/LongListDataType.java
@@ -38,7 +38,7 @@ public class LongListDataType implements DataType<List<Long>> 
{
   public void write(final ByteBuffer buffer, final int position, final 
List<Long> values) {
     buffer.putInt(position, size(values));
     var p = position + Integer.BYTES;
-    for (Long value : values) {
+    for (long value : values) {
       buffer.putLong(p, value);
       p += Long.BYTES;
     }
@@ -47,11 +47,12 @@ public class LongListDataType implements 
DataType<List<Long>> {
   /** {@inheritDoc} */
   @Override
   public List<Long> read(final ByteBuffer buffer, final int position) {
-    var size = buffer.getInt(position);
-    var list = new ArrayList<Long>(size);
-    for (var p = position + Integer.BYTES; p < position + size; p += 
Long.BYTES) {
-      list.add(buffer.getLong(p));
+    int size = buffer.getInt(position);
+    int length = (size - Integer.BYTES) / Long.BYTES;
+    var values = new ArrayList<Long>(length);
+    for (int index = 0; index < length; index++) {
+      values.add(buffer.getLong(position + Integer.BYTES + index * 
Long.BYTES));
     }
-    return list;
+    return values;
   }
 }
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/MapDataType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/MapDataType.java
index cc663279..c738ca84 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/MapDataType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/MapDataType.java
@@ -45,7 +45,7 @@ public class MapDataType<K, V> implements DataType<Map<K, V>> 
{
   @Override
   public void write(final ByteBuffer buffer, final int position, final Map<K, 
V> value) {
     buffer.putInt(position, size(value));
-    var p = position + Integer.BYTES;
+    int p = position + Integer.BYTES;
     for (Map.Entry<K, V> entry : value.entrySet()) {
       keyType.write(buffer, p, entry.getKey());
       p += keyType.size(entry.getKey());
@@ -57,7 +57,7 @@ public class MapDataType<K, V> implements DataType<Map<K, V>> 
{
   @Override
   public Map<K, V> read(final ByteBuffer buffer, final int position) {
     int size = buffer.getInt(position);
-    Map<K, V> map = new HashMap<>(size);
+    var map = new HashMap<K, V>(size);
     for (int p = position + Integer.BYTES; p < position + size;) {
       K key = keyType.read(buffer, p);
       p += keyType.size(key);
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/PairDataType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/PairDataType.java
index 0a1485fc..9e51bc28 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/PairDataType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/PairDataType.java
@@ -70,12 +70,10 @@ public class PairDataType<L, R> extends 
FixedSizeDataType<Pair<L, R>> {
       if (this == o) {
         return true;
       }
-      if (!(o instanceof PairDataType.Pair)) {
+      if (!(o instanceof Pair<?, ?> pair)) {
         return false;
       }
 
-      Pair<?, ?> pair = (Pair<?, ?>) o;
-
       if (!Objects.equals(left, pair.left)) {
         return false;
       }
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/RowDataType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/RowDataType.java
index b734ad14..b7f90492 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/RowDataType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/RowDataType.java
@@ -56,7 +56,7 @@ public class RowDataType implements DataType<DataRow> {
 
   @Override
   public int size(final DataRow dataRow) {
-    var size = Integer.BYTES;
+    int size = Integer.BYTES;
     var columns = dataSchema.columns();
     for (int i = 0; i < columns.size(); i++) {
       var columnType = columns.get(i).type();
@@ -74,7 +74,7 @@ public class RowDataType implements DataType<DataRow> {
 
   @Override
   public void write(final ByteBuffer buffer, final int position, final DataRow 
dataRow) {
-    var p = position + Integer.BYTES;
+    int p = position + Integer.BYTES;
     var columns = dataSchema.columns();
     for (int i = 0; i < columns.size(); i++) {
       var column = columns.get(i);
@@ -89,7 +89,7 @@ public class RowDataType implements DataType<DataRow> {
 
   @Override
   public DataRow read(final ByteBuffer buffer, final int position) {
-    var p = position + Integer.BYTES;
+    int p = position + Integer.BYTES;
     var columns = dataSchema.columns();
     var values = new ArrayList();
     for (DataColumn column : columns) {
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ShortListDataType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ShortArrayDataType.java
similarity index 65%
copy from 
baremaps-core/src/main/java/org/apache/baremaps/collection/type/ShortListDataType.java
copy to 
baremaps-core/src/main/java/org/apache/baremaps/collection/type/ShortArrayDataType.java
index 46ef5566..55e10496 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ShortListDataType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ShortArrayDataType.java
@@ -15,16 +15,14 @@ package org.apache.baremaps.collection.type;
 
 
 import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
 
 /** A {@link DataType} for reading and writing lists of shorts in {@link 
ByteBuffer}s. */
-public class ShortListDataType implements DataType<List<Short>> {
+public class ShortArrayDataType implements DataType<short[]> {
 
   /** {@inheritDoc} */
   @Override
-  public int size(final List<Short> values) {
-    return Integer.BYTES + values.size() * Short.BYTES;
+  public int size(final short[] values) {
+    return Integer.BYTES + values.length * Short.BYTES;
   }
 
   /** {@inheritDoc} */
@@ -35,10 +33,10 @@ public class ShortListDataType implements 
DataType<List<Short>> {
 
   /** {@inheritDoc} */
   @Override
-  public void write(final ByteBuffer buffer, final int position, final 
List<Short> values) {
+  public void write(final ByteBuffer buffer, final int position, final short[] 
values) {
     buffer.putInt(position, size(values));
-    var p = position + Integer.BYTES;
-    for (Short value : values) {
+    int p = position + Integer.BYTES;
+    for (short value : values) {
       buffer.putShort(p, value);
       p += Short.BYTES;
     }
@@ -46,12 +44,13 @@ public class ShortListDataType implements 
DataType<List<Short>> {
 
   /** {@inheritDoc} */
   @Override
-  public List<Short> read(final ByteBuffer buffer, final int position) {
-    var size = buffer.getInt(position);
-    var list = new ArrayList<Short>(size);
-    for (var p = position + Integer.BYTES; p < position + size; p += 
Short.BYTES) {
-      list.add(buffer.getShort(p));
+  public short[] read(final ByteBuffer buffer, final int position) {
+    int size = buffer.getInt(position);
+    int length = (size - Integer.BYTES) / Short.BYTES;
+    short[] values = new short[length];
+    for (int index = 0; index < length; index++) {
+      values[index] = buffer.getShort(position + Integer.BYTES + index * 
Short.BYTES);
     }
-    return list;
+    return values;
   }
 }
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ShortListDataType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ShortListDataType.java
index 46ef5566..dca365b9 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ShortListDataType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/ShortListDataType.java
@@ -37,8 +37,8 @@ public class ShortListDataType implements 
DataType<List<Short>> {
   @Override
   public void write(final ByteBuffer buffer, final int position, final 
List<Short> values) {
     buffer.putInt(position, size(values));
-    var p = position + Integer.BYTES;
-    for (Short value : values) {
+    int p = position + Integer.BYTES;
+    for (short value : values) {
       buffer.putShort(p, value);
       p += Short.BYTES;
     }
@@ -47,11 +47,12 @@ public class ShortListDataType implements 
DataType<List<Short>> {
   /** {@inheritDoc} */
   @Override
   public List<Short> read(final ByteBuffer buffer, final int position) {
-    var size = buffer.getInt(position);
-    var list = new ArrayList<Short>(size);
-    for (var p = position + Integer.BYTES; p < position + size; p += 
Short.BYTES) {
-      list.add(buffer.getShort(p));
+    int size = buffer.getInt(position);
+    int length = (size - Integer.BYTES) / Short.BYTES;
+    var values = new ArrayList<Short>(length);
+    for (int index = 0; index < length; index++) {
+      values.add(buffer.getShort(position + Integer.BYTES + index * 
Short.BYTES));
     }
-    return list;
+    return values;
   }
 }
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/StringDataType.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/StringDataType.java
index 8b50ad8c..ef0c0325 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/collection/type/StringDataType.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/collection/type/StringDataType.java
@@ -37,7 +37,7 @@ public class StringDataType implements DataType<String> {
   /** {@inheritDoc} */
   @Override
   public void write(final ByteBuffer buffer, final int position, final String 
value) {
-    var bytes = value.getBytes(StandardCharsets.UTF_8);
+    byte[] bytes = value.getBytes(StandardCharsets.UTF_8);
     buffer.putInt(position, size(value));
     buffer.put(position + Integer.BYTES, bytes, 0, bytes.length);
   }
@@ -45,8 +45,8 @@ public class StringDataType implements DataType<String> {
   /** {@inheritDoc} */
   @Override
   public String read(final ByteBuffer buffer, final int position) {
-    var size = size(buffer, position);
-    var bytes = new byte[Math.max(size - Integer.BYTES, 0)];
+    int size = size(buffer, position);
+    byte[] bytes = new byte[Math.max(size - Integer.BYTES, 0)];
     buffer.get(position + Integer.BYTES, bytes);
     return new String(bytes, StandardCharsets.UTF_8);
   }
diff --git 
a/baremaps-core/src/test/java/org/apache/baremaps/collection/type/DataTypeProvider.java
 
b/baremaps-core/src/test/java/org/apache/baremaps/collection/type/DataTypeProvider.java
index 63f74014..c9052279 100644
--- 
a/baremaps-core/src/test/java/org/apache/baremaps/collection/type/DataTypeProvider.java
+++ 
b/baremaps-core/src/test/java/org/apache/baremaps/collection/type/DataTypeProvider.java
@@ -84,6 +84,14 @@ public class DataTypeProvider {
         Arguments.of(new StringDataType(), ""),
         Arguments.of(new StringDataType(), "Hello, World!"),
 
+        // Boolean
+        Arguments.of(new BooleanDataType(), true),
+        Arguments.of(new BooleanDataType(), false),
+        Arguments.of(new BooleanArrayDataType(), new boolean[] {}),
+        Arguments.of(new BooleanArrayDataType(), new boolean[] {true, false}),
+        Arguments.of(new BooleanListDataType(), List.of()),
+        Arguments.of(new BooleanListDataType(), List.of(true, false)),
+
         // Byte
         Arguments.of(new ByteDataType(), Byte.MIN_VALUE),
         Arguments.of(new ByteDataType(), Byte.MAX_VALUE),
@@ -119,6 +127,8 @@ public class DataTypeProvider {
         Arguments.of(new FloatDataType(), 0f),
         Arguments.of(new FloatDataType(), 1f),
         Arguments.of(new FloatDataType(), -1f),
+        Arguments.of(new FloatArrayDataType(), new float[] {}),
+        Arguments.of(new FloatArrayDataType(), new float[] {(float) 1, (float) 
2, (float) 3}),
         Arguments.of(new FloatListDataType(), List.of()),
         Arguments.of(new FloatListDataType(), List.of((float) 1, (float) 2, 
(float) 3)),
 
@@ -128,6 +138,8 @@ public class DataTypeProvider {
         Arguments.of(new IntegerDataType(), 0),
         Arguments.of(new IntegerDataType(), 1),
         Arguments.of(new IntegerDataType(), -1),
+        Arguments.of(new IntegerArrayDataType(), new int[] {}),
+        Arguments.of(new IntegerArrayDataType(), new int[] {1, 2, 3}),
         Arguments.of(new IntegerListDataType(), List.of()),
         Arguments.of(new IntegerListDataType(), List.of(1, 2, 3)),
 
@@ -137,6 +149,8 @@ public class DataTypeProvider {
         Arguments.of(new LongDataType(), 0l),
         Arguments.of(new LongDataType(), 1l),
         Arguments.of(new LongDataType(), -1l),
+        Arguments.of(new LongArrayDataType(), new long[] {}),
+        Arguments.of(new LongArrayDataType(), new long[] {1l, 2l, 3l}),
         Arguments.of(new LongListDataType(), List.of()),
         Arguments.of(new LongListDataType(), List.of(1l, 2l, 3l)),
 
@@ -146,6 +160,8 @@ public class DataTypeProvider {
         Arguments.of(new ShortDataType(), (short) 0),
         Arguments.of(new ShortDataType(), (short) 1),
         Arguments.of(new ShortDataType(), (short) -1),
+        Arguments.of(new ShortArrayDataType(), new short[] {}),
+        Arguments.of(new ShortArrayDataType(), new short[] {(short) 1, (short) 
2, (short) 3}),
         Arguments.of(new ShortListDataType(), List.of()),
         Arguments.of(new ShortListDataType(), List.of((short) 1, (short) 2, 
(short) 3)),
 


Reply via email to