You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by le...@apache.org on 2024/07/07 21:48:26 UTC
(datasketches-memory) branch prepare_for_3.0.0 created (now e7c23b7)
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a change to branch prepare_for_3.0.0
in repository https://gitbox.apache.org/repos/asf/datasketches-memory.git
at e7c23b7 Changes to bring 2.2.0, 3.0.0 and 4.0.0 into alignment.
This branch includes the following new commits:
new e7c23b7 Changes to bring 2.2.0, 3.0.0 and 4.0.0 into alignment.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org
(datasketches-memory) 01/01: Changes to bring 2.2.0, 3.0.0 and 4.0.0 into alignment.
Posted by le...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch prepare_for_3.0.0
in repository https://gitbox.apache.org/repos/asf/datasketches-memory.git
commit e7c23b7783e070b5fb96de86b33921ca1a07d83e
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Sun Jul 7 14:48:06 2024 -0700
Changes to bring 2.2.0, 3.0.0 and 4.0.0 into alignment.
---
LICENSE | 50 +-----
NOTICE | 2 +-
datasketches-memory-java11/pom.xml | 179 +++++++++++----------
datasketches-memory-java8/pom.xml | 43 +++--
.../org/apache/datasketches/memory/Buffer.java | 54 +++++--
.../memory/DefaultMemoryRequestServer.java | 12 +-
.../org/apache/datasketches/memory/Memory.java | 96 ++++++++---
.../datasketches/memory/MemoryRequestServer.java | 8 +-
.../apache/datasketches/memory/MurmurHash3v2.java | 45 ++++--
.../org/apache/datasketches/memory/Positional.java | 5 +-
.../org/apache/datasketches/memory/Resource.java | 21 ++-
.../apache/datasketches/memory/WritableBuffer.java | 79 ++++++---
.../apache/datasketches/memory/WritableMemory.java | 3 -
.../org/apache/datasketches/memory/XxHash.java | 61 ++++---
.../memory/internal/BaseWritableBufferImpl.java | 4 +-
.../memory/internal/BaseWritableMemoryImpl.java | 3 +
.../datasketches/memory/internal/ResourceImpl.java | 3 +-
.../memory/internal/IsValidUtf8TestUtil.java | 64 --------
.../datasketches/memory/internal/MemoryTest.java | 25 +++
pom.xml | 72 ++++-----
tools/scripts/assets/CheckMemoryJar.java | 12 +-
21 files changed, 469 insertions(+), 372 deletions(-)
diff --git a/LICENSE b/LICENSE
index 61f8cad..1f00f5c 100644
--- a/LICENSE
+++ b/LICENSE
@@ -252,54 +252,6 @@ APPENDIX B: Additional licenses relevant to this product:
- =============================================================
- Google Protobuf License:
- =============================================================
- Copyright 2008 Google Inc.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following disclaimer
- in the documentation and/or other materials provided with the
- distribution.
- * Neither the name of Google Inc. nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- Code generated by the Protocol Buffer compiler is owned by the owner
- of the input file used when generating it. This code is not
- standalone and requires a support library to be linked with it. This
- support library is itself covered by the above license.
-
- Code locations:
- -------------------------------------------------------------
- This product contains code for encoding, decoding and testing UTF8:
- * datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Utf8.java
- * datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/Utf8Test.java
- * datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/IsValidUtf8TestUtil.java
- and adapted from Java source code located at:
- * https://github.com/protocolbuffers/protobuf/blob/master/java/core/src/main/java/com/google/protobuf/Utf8.java,
- * https://github.com/protocolbuffers/protobuf/blob/master/java/core/src/test/java/com/google/protobuf/Utf8Test.java,
- * https://github.com/protocolbuffers/protobuf/blob/master/java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java,
-
-
-
=============================================================
BSD-2-Clause License
=============================================================
@@ -330,7 +282,7 @@ APPENDIX B: Additional licenses relevant to this product:
Code locations:
-------------------------------------------------------------
- This product contains code for encoding, decoding and testing UTF8:
+ This product contains code for encoding, decoding and testing xxHash:
* datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/XxHash64.java
and adapted from C++ code located at:
* https://github.com/Cyan4973/xxHash/blob/dev/xxhash.c,
diff --git a/NOTICE b/NOTICE
index e69ad8a..7218127 100644
--- a/NOTICE
+++ b/NOTICE
@@ -1,5 +1,5 @@
Apache DataSketches Memory
-Copyright 2022 - The Apache Software Foundation
+Copyright 2024 - The Apache Software Foundation
Copyright 2015-2018 Yahoo Inc.
Copyright 2019-2020 Verizon Media
diff --git a/datasketches-memory-java11/pom.xml b/datasketches-memory-java11/pom.xml
index e03f90e..8ec9bc9 100644
--- a/datasketches-memory-java11/pom.xml
+++ b/datasketches-memory-java11/pom.xml
@@ -1,101 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- ~ 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.
- -->
+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.
+-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
+ <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.datasketches</groupId>
- <artifactId>datasketches-memory-root</artifactId>
- <version>3.0.0-SNAPSHOT</version>
- </parent>
+ <parent>
+ <groupId>org.apache.datasketches</groupId>
+ <artifactId>datasketches-memory-root</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
- <artifactId>datasketches-memory-java11</artifactId>
- <name>${project.artifactId}</name>
- <packaging>jar</packaging>
+ <artifactId>datasketches-memory-java11</artifactId>
+ <name>${project.artifactId}</name>
+ <packaging>jar</packaging>
- <properties>
- <java.version>11</java.version>
- <jdk-toolchain.version>11</jdk-toolchain.version>
- <maven.compiler.source>${java.version}</maven.compiler.source>
- <maven.compiler.target>${java.version}</maven.compiler.target>
- </properties>
+ <properties>
+ <java.version>11</java.version>
+ <jdk-toolchain.version>11</jdk-toolchain.version>
+ <maven.compiler.source>${java.version}</maven.compiler.source>
+ <maven.compiler.target>${java.version}</maven.compiler.target>
+ <maven.javadoc.skip>true</maven.javadoc.skip>
+ </properties>
- <build>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>${maven-compiler-plugin.version}</version>
- <configuration>
- <compilerArgs>
- <arg>--add-exports</arg>
- <arg>java.base/jdk.internal.ref=org.apache.datasketches.memory</arg>
- </compilerArgs>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>${maven-compiler-plugin.version}</version>
+ <configuration>
+ <compilerArgs>
+ <arg>--add-exports</arg>
+ <arg>java.base/jdk.internal.ref=org.apache.datasketches.memory</arg>
+ </compilerArgs>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
- <profiles>
- <profile>
- <id>assemble-mr-jar</id>
- <activation>
- <property>
- <name>!unsetDefaultProfile</name>
- </property>
- </activation>
- <properties>
- <assembly.script.path>${maven.multiModuleProjectDirectory}/tools/scripts/package-multi-release-jar.sh</assembly.script.path>
- <assembly.java.home>${env.JAVA_HOME}</assembly.java.home>
- <assembly.git.tag>${project.version}</assembly.git.tag>
- <assembly.base.dir>${maven.multiModuleProjectDirectory}</assembly.base.dir>
- </properties>
- <build>
- <defaultGoal>exec:exec</defaultGoal>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>exec-maven-plugin</artifactId>
- <!-- The trailing comment on the line below ignores an eclipse warning. The version is required for dependency updates. -->
- <version>${maven-exec-plugin.version}</version><!--$NO-MVN-MAN-VER$-->
- <executions>
- <execution>
- <id>package-mr-jar</id>
- <goals>
- <goal>exec</goal>
- </goals>
- <phase>package</phase>
- <configuration>
- <executable>bash</executable>
- <commandlineArgs>${assembly.script.path} ${assembly.java.home} ${assembly.git.tag} ${assembly.base.dir}</commandlineArgs>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
+ <profiles>
+ <profile>
+ <id>assemble-mr-jar</id>
+ <activation>
+ <property>
+ <name>!unsetDefaultProfile</name>
+ </property>
+ </activation>
+ <properties>
+ <assembly.script.path>${maven.multiModuleProjectDirectory}/tools/scripts/package-multi-release-jar.sh</assembly.script.path>
+ <assembly.java.home>${env.JAVA_HOME}</assembly.java.home>
+ <assembly.git.tag>${project.version}</assembly.git.tag>
+ <assembly.base.dir>${maven.multiModuleProjectDirectory}</assembly.base.dir>
+ </properties>
+ <build>
+ <defaultGoal>exec:exec</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <!-- The trailing comment on the line below ignores an eclipse warning. The version is required for dependency updates. -->
+ <version>${exec-maven-plugin.version}</version><!--$NO-MVN-MAN-VER$-->
+ <executions>
+ <execution>
+ <id>package-mr-jar</id>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <executable>bash</executable>
+ <commandlineArgs>${assembly.script.path} ${assembly.java.home} ${assembly.git.tag} ${assembly.base.dir}</commandlineArgs>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
</project>
diff --git a/datasketches-memory-java8/pom.xml b/datasketches-memory-java8/pom.xml
index 00ff8d0..bce79b5 100644
--- a/datasketches-memory-java8/pom.xml
+++ b/datasketches-memory-java8/pom.xml
@@ -1,22 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- ~ 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.
- -->
+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.
+-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -33,11 +33,10 @@
<packaging>jar</packaging>
<properties>
- <java.version>1.8</java.version>
+ <java.version>8</java.version>
<jdk-toolchain.version>8</jdk-toolchain.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
- <!-- override javadoc for this module only -->
<maven.javadoc.skip>false</maven.javadoc.skip>
</properties>
@@ -47,12 +46,6 @@
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <!-- Used for UTF8 testing -->
- <groupId>com.google.protobuf</groupId>
- <artifactId>protobuf-java</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<!-- Used for xxHash testing -->
<groupId>net.openhft</groupId>
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Buffer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Buffer.java
index 542676e..898c539 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Buffer.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Buffer.java
@@ -57,7 +57,9 @@ public interface Buffer extends Positional {
* @param byteOrder the ByteOrder to be used. It must be non-null.
* @return a new <i>Buffer</i> for read-only operations on the given ByteBuffer.
*/
- static Buffer wrap(ByteBuffer byteBuffer, ByteOrder byteOrder) {
+ static Buffer wrap(
+ ByteBuffer byteBuffer,
+ ByteOrder byteOrder) {
return BaseWritableBufferImpl.wrapByteBuffer(byteBuffer, true, byteOrder, null);
}
@@ -143,7 +145,10 @@ public interface Buffer extends Positional {
* @return a new <i>Buffer</i> representing the defined writable region
* based on the current <i>position</i>, <i>end</i> and byteOrder.
*/
- Buffer region(long offsetBytes, long capacityBytes, ByteOrder byteOrder);
+ Buffer region(
+ long offsetBytes,
+ long capacityBytes,
+ ByteOrder byteOrder);
//AS MEMORY
/**
@@ -207,7 +212,10 @@ public interface Buffer extends Positional {
* @param dstOffsetBytes offset in array units
* @param lengthBytes number of array units to transfer
*/
- void getByteArray(byte[] dstArray, int dstOffsetBytes, int lengthBytes);
+ void getByteArray(
+ byte[] dstArray,
+ int dstOffsetBytes,
+ int lengthBytes);
/**
* Gets the char value at the current position.
@@ -231,7 +239,10 @@ public interface Buffer extends Positional {
* @param dstOffsetChars offset in array units
* @param lengthChars number of array units to transfer
*/
- void getCharArray(char[] dstArray, int dstOffsetChars, int lengthChars);
+ void getCharArray(
+ char[] dstArray,
+ int dstOffsetChars,
+ int lengthChars);
/**
* Gets the double value at the current position.
@@ -255,7 +266,10 @@ public interface Buffer extends Positional {
* @param dstOffsetDoubles offset in array units
* @param lengthDoubles number of array units to transfer
*/
- void getDoubleArray(double[] dstArray, int dstOffsetDoubles, int lengthDoubles);
+ void getDoubleArray(
+ double[] dstArray,
+ int dstOffsetDoubles,
+ int lengthDoubles);
/**
* Gets the float value at the current position.
@@ -279,7 +293,10 @@ public interface Buffer extends Positional {
* @param dstOffsetFloats offset in array units
* @param lengthFloats number of array units to transfer
*/
- void getFloatArray(float[] dstArray, int dstOffsetFloats, int lengthFloats);
+ void getFloatArray(
+ float[] dstArray,
+ int dstOffsetFloats,
+ int lengthFloats);
/**
* Gets the int value at the current position.
@@ -303,7 +320,10 @@ public interface Buffer extends Positional {
* @param dstOffsetInts offset in array units
* @param lengthInts number of array units to transfer
*/
- void getIntArray(int[] dstArray, int dstOffsetInts, int lengthInts);
+ void getIntArray(
+ int[] dstArray,
+ int dstOffsetInts,
+ int lengthInts);
/**
* Gets the long value at the current position.
@@ -327,7 +347,10 @@ public interface Buffer extends Positional {
* @param dstOffsetLongs offset in array units
* @param lengthLongs number of array units to transfer
*/
- void getLongArray(long[] dstArray, int dstOffsetLongs, int lengthLongs);
+ void getLongArray(
+ long[] dstArray,
+ int dstOffsetLongs,
+ int lengthLongs);
/**
* Gets the short value at the current position.
@@ -351,10 +374,13 @@ public interface Buffer extends Positional {
* @param dstOffsetShorts offset in array units
* @param lengthShorts number of array units to transfer
*/
- void getShortArray(short[] dstArray, int dstOffsetShorts, int lengthShorts);
+ void getShortArray(
+ short[] dstArray,
+ int dstOffsetShorts,
+ int lengthShorts);
//SPECIAL PRIMITIVE READ METHODS: compareTo.
- // No copyTo, No writeTo. Use Memory for that.
+ // No copyTo, No writeTo. Use Memory for those.
/**
* Compares the bytes of this Buffer to <i>that</i> Buffer.
@@ -371,7 +397,11 @@ public interface Buffer extends Positional {
* @return <i>(this < that) ? (some negative value) : (this > that) ? (some positive value)
* : 0;</i>
*/
- int compareTo(long thisOffsetBytes, long thisLengthBytes, Buffer that,
- long thatOffsetBytes, long thatLengthBytes);
+ int compareTo(
+ long thisOffsetBytes,
+ long thisLengthBytes,
+ Buffer that,
+ long thatOffsetBytes,
+ long thatLengthBytes);
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java
index 8844f57..8d405a8 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java
@@ -46,13 +46,17 @@ public final class DefaultMemoryRequestServer implements MemoryRequestServer {
* @param copyOldToNew if true, the data from the current memory will be copied to the new memory,
* starting at address 0, and through the currentMemory capacity.
*/
- public DefaultMemoryRequestServer(final boolean offHeap, final boolean copyOldToNew) {
+ public DefaultMemoryRequestServer(
+ final boolean offHeap,
+ final boolean copyOldToNew) {
this.offHeap = offHeap;
this.copyOldToNew = copyOldToNew;
}
@Override
- public WritableMemory request(final WritableMemory currentWmem, final long newCapacityBytes) {
+ public WritableMemory request(
+ final WritableMemory currentWmem,
+ final long newCapacityBytes) {
final ByteOrder order = currentWmem.getTypeByteOrder();
final long currentBytes = currentWmem.getCapacity();
final WritableMemory newWmem;
@@ -79,7 +83,9 @@ public final class DefaultMemoryRequestServer implements MemoryRequestServer {
}
@Override
- public void requestClose(final WritableMemory memToClose, final WritableMemory newMemory) {
+ public void requestClose(
+ final WritableMemory memToClose,
+ final WritableMemory newMemory) {
if (memToClose.isCloseable()) { memToClose.close(); }
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Memory.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Memory.java
index 45e0a67..b086c6c 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Memory.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Memory.java
@@ -28,7 +28,6 @@ import java.util.Objects;
import org.apache.datasketches.memory.internal.BaseWritableMemoryImpl;
import org.apache.datasketches.memory.internal.Prim;
-import org.apache.datasketches.memory.internal.ResourceImpl;
/**
* Defines the read-only API for offset access to a resource.
@@ -60,7 +59,9 @@ public interface Memory extends Resource {
* @param byteOrder the byte order to be used. It must be non-null.
* @return a new <i>Memory</i> for read-only operations on the given <i>ByteBuffer</i>.
*/
- static Memory wrap(ByteBuffer byteBuffer, ByteOrder byteOrder) {
+ static Memory wrap(
+ ByteBuffer byteBuffer,
+ ByteOrder byteOrder) {
return BaseWritableMemoryImpl.wrapByteBuffer(byteBuffer, true, byteOrder, null);
}
@@ -95,7 +96,11 @@ public interface Memory extends Resource {
* @throws SecurityException If a security manager is installed and it denies an unspecified permission
* required by the implementation.
*/
- static Memory map(File file, long fileOffsetBytes, long capacityBytes, ByteOrder byteOrder) throws IOException {
+ static Memory map(
+ File file,
+ long fileOffsetBytes,
+ long capacityBytes,
+ ByteOrder byteOrder) throws IOException {
return BaseWritableMemoryImpl.wrapMap(file, fileOffsetBytes, capacityBytes, true, byteOrder);
}
@@ -113,7 +118,9 @@ public interface Memory extends Resource {
* @return a new <i>Memory</i> representing the defined region based on the given
* offsetBytes and capacityBytes.
*/
- default Memory region(long offsetBytes, long capacityBytes) {
+ default Memory region(
+ long offsetBytes,
+ long capacityBytes) {
return region(offsetBytes, capacityBytes, getTypeByteOrder());
}
@@ -130,7 +137,10 @@ public interface Memory extends Resource {
* @return a new <i>Memory</i> representing the defined region based on the given
* offsetBytes, capacityBytes and byteOrder.
*/
- Memory region(long offsetBytes, long capacityBytes, ByteOrder byteOrder);
+ Memory region(
+ long offsetBytes,
+ long capacityBytes,
+ ByteOrder byteOrder);
//AS BUFFER
/**
@@ -184,7 +194,9 @@ public interface Memory extends Resource {
* @param byteOrder the byte order to be used. It must be non-null.
* @return a new <i>Memory</i> for read operations
*/
- static Memory wrap(byte[] array, ByteOrder byteOrder) {
+ static Memory wrap(
+ byte[] array,
+ ByteOrder byteOrder) {
return wrap(array, 0, array.length, byteOrder);
}
@@ -196,10 +208,12 @@ public interface Memory extends Resource {
* @param byteOrder the byte order to be used. It must be non-null.
* @return a new <i>Memory</i> for read operations
*/
- static Memory wrap(byte[] array, int offsetBytes, int lengthBytes, ByteOrder byteOrder) {
- Objects.requireNonNull(array, "array must be non-null");
- ResourceImpl.checkBounds(offsetBytes, lengthBytes, array.length);
- return BaseWritableMemoryImpl.wrapHeapArray(array, offsetBytes, lengthBytes, true, ByteOrder.nativeOrder(), null);
+ static Memory wrap(
+ byte[] array,
+ int offsetBytes,
+ int lengthBytes,
+ ByteOrder byteOrder) {
+ return BaseWritableMemoryImpl.wrapHeapArray(array, offsetBytes, lengthBytes, true, byteOrder, null);
}
/**
@@ -292,7 +306,11 @@ public interface Memory extends Resource {
* @param dstOffsetBytes offset in array units
* @param lengthBytes number of array units to transfer
*/
- void getByteArray(long offsetBytes, byte[] dstArray, int dstOffsetBytes, int lengthBytes);
+ void getByteArray(
+ long offsetBytes,
+ byte[] dstArray,
+ int dstOffsetBytes,
+ int lengthBytes);
/**
* Gets the char value at the given offset
@@ -308,7 +326,11 @@ public interface Memory extends Resource {
* @param dstOffsetChars offset in array units
* @param lengthChars number of array units to transfer
*/
- void getCharArray(long offsetBytes, char[] dstArray, int dstOffsetChars, int lengthChars);
+ void getCharArray(
+ long offsetBytes,
+ char[] dstArray,
+ int dstOffsetChars,
+ int lengthChars);
/**
* Gets the double value at the given offset
@@ -324,7 +346,11 @@ public interface Memory extends Resource {
* @param dstOffsetDoubles offset in array units
* @param lengthDoubles number of array units to transfer
*/
- void getDoubleArray(long offsetBytes, double[] dstArray, int dstOffsetDoubles, int lengthDoubles);
+ void getDoubleArray(
+ long offsetBytes,
+ double[] dstArray,
+ int dstOffsetDoubles,
+ int lengthDoubles);
/**
* Gets the float value at the given offset
@@ -340,7 +366,11 @@ public interface Memory extends Resource {
* @param dstOffsetFloats offset in array units
* @param lengthFloats number of array units to transfer
*/
- void getFloatArray(long offsetBytes, float[] dstArray, int dstOffsetFloats, int lengthFloats);
+ void getFloatArray(
+ long offsetBytes,
+ float[] dstArray,
+ int dstOffsetFloats,
+ int lengthFloats);
/**
* Gets the int value at the given offset
@@ -356,7 +386,11 @@ public interface Memory extends Resource {
* @param dstOffsetInts offset in array units
* @param lengthInts number of array units to transfer
*/
- void getIntArray(long offsetBytes, int[] dstArray, int dstOffsetInts, int lengthInts);
+ void getIntArray(
+ long offsetBytes,
+ int[] dstArray,
+ int dstOffsetInts,
+ int lengthInts);
/**
* Gets the long value at the given offset
@@ -372,7 +406,11 @@ public interface Memory extends Resource {
* @param dstOffsetLongs offset in array units
* @param lengthLongs number of array units to transfer
*/
- void getLongArray(long offsetBytes, long[] dstArray, int dstOffsetLongs, int lengthLongs);
+ void getLongArray(
+ long offsetBytes,
+ long[] dstArray,
+ int dstOffsetLongs,
+ int lengthLongs);
/**
* Gets the short value at the given offset
@@ -388,7 +426,11 @@ public interface Memory extends Resource {
* @param dstOffsetShorts offset in array units
* @param lengthShorts number of array units to transfer
*/
- void getShortArray(long offsetBytes, short[] dstArray, int dstOffsetShorts, int lengthShorts);
+ void getShortArray(
+ long offsetBytes,
+ short[] dstArray,
+ int dstOffsetShorts,
+ int lengthShorts);
//SPECIAL PRIMITIVE READ METHODS: compareTo, copyTo, writeTo
@@ -406,8 +448,12 @@ public interface Memory extends Resource {
* @return <i>(this < that) ? (some negative value) : (this > that) ? (some positive value)
* : 0;</i>
*/
- int compareTo(long thisOffsetBytes, long thisLengthBytes, Memory that,
- long thatOffsetBytes, long thatLengthBytes);
+ int compareTo(
+ long thisOffsetBytes,
+ long thisLengthBytes,
+ Memory that,
+ long thatOffsetBytes,
+ long thatLengthBytes);
/**
* Copies bytes from a source range of this Memory to a destination range of the given Memory
@@ -421,7 +467,11 @@ public interface Memory extends Resource {
* @param dstOffsetBytes the destination offset
* @param lengthBytes the number of bytes to copy
*/
- void copyTo(long srcOffsetBytes, WritableMemory destination, long dstOffsetBytes, long lengthBytes);
+ void copyTo(
+ long srcOffsetBytes,
+ WritableMemory destination,
+ long dstOffsetBytes,
+ long lengthBytes);
/**
* Writes bytes from a source range of this Memory to the given {@code WritableByteChannel}.
@@ -430,7 +480,9 @@ public interface Memory extends Resource {
* @param out the destination WritableByteChannel
* @throws IOException may occur while writing to the WritableByteChannel
*/
- void writeTo(long offsetBytes, long lengthBytes, WritableByteChannel out)
- throws IOException;
+ void writeTo(
+ long offsetBytes,
+ long lengthBytes,
+ WritableByteChannel out) throws IOException;
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MemoryRequestServer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MemoryRequestServer.java
index 9782b77..814aa72 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MemoryRequestServer.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MemoryRequestServer.java
@@ -35,7 +35,9 @@ public interface MemoryRequestServer {
*
* @return new WritableMemory with the requested capacity.
*/
- WritableMemory request(WritableMemory currentWritableMemory, long newCapacityBytes);
+ WritableMemory request(
+ WritableMemory currentWritableMemory,
+ long newCapacityBytes);
/**
* Request to close the resource, if applicable.
@@ -54,6 +56,8 @@ public interface MemoryRequestServer {
* The newMemory reference is returned from the client for the convenience of the system that
* owns the responsibility of memory allocation. It may be null.
*/
- void requestClose(final WritableMemory memToClose, WritableMemory newMemory);
+ void requestClose(
+ final WritableMemory memToClose,
+ WritableMemory newMemory);
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MurmurHash3v2.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MurmurHash3v2.java
index 9c5a35b..7d6136d 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MurmurHash3v2.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MurmurHash3v2.java
@@ -54,7 +54,9 @@ public final class MurmurHash3v2 {
* @param seed A long valued seed.
* @return the hash
*/
- public static long[] hash(final long[] in, final long seed) {
+ public static long[] hash(
+ final long[] in,
+ final long seed) {
if ((in == null) || (in.length == 0)) {
throw new IllegalArgumentException("Input in is empty or null.");
}
@@ -69,7 +71,9 @@ public final class MurmurHash3v2 {
* @param seed A long valued seed.
* @return the hash
*/
- public static long[] hash(final int[] in, final long seed) {
+ public static long[] hash(
+ final int[] in,
+ final long seed) {
if ((in == null) || (in.length == 0)) {
throw new IllegalArgumentException("Input in is empty or null.");
}
@@ -84,7 +88,9 @@ public final class MurmurHash3v2 {
* @param seed A long valued seed.
* @return the hash
*/
- public static long[] hash(final char[] in, final long seed) {
+ public static long[] hash(
+ final char[] in,
+ final long seed) {
if ((in == null) || (in.length == 0)) {
throw new IllegalArgumentException("Input in is empty or null.");
}
@@ -99,7 +105,9 @@ public final class MurmurHash3v2 {
* @param seed A long valued seed.
* @return the hash
*/
- public static long[] hash(final byte[] in, final long seed) {
+ public static long[] hash(
+ final byte[] in,
+ final long seed) {
if ((in == null) || (in.length == 0)) {
throw new IllegalArgumentException("Input in is empty or null.");
}
@@ -116,7 +124,10 @@ public final class MurmurHash3v2 {
* @param hashOut A long array of size 2
* @return the hash
*/
- public static long[] hash(final long in, final long seed, final long[] hashOut) {
+ public static long[] hash(
+ final long in,
+ final long seed,
+ final long[] hashOut) {
final long h1 = seed ^ mixK1(in);
final long h2 = seed;
return finalMix128(h1, h2, 8, hashOut);
@@ -130,7 +141,10 @@ public final class MurmurHash3v2 {
* @param hashOut A long array of size 2
* @return the hash
*/
- public static long[] hash(final double in, final long seed, final long[] hashOut) {
+ public static long[] hash(
+ final double in,
+ final long seed,
+ final long[] hashOut) {
final double d = (in == 0.0) ? 0.0 : in; // canonicalize -0.0, 0.0
final long k1 = Double.doubleToLongBits(d); // canonicalize all NaN forms
final long h1 = seed ^ mixK1(k1);
@@ -146,7 +160,10 @@ public final class MurmurHash3v2 {
* @param hashOut A long array of size 2
* @return the hash
*/
- public static long[] hash(final String in, final long seed, final long[] hashOut) {
+ public static long[] hash(
+ final String in,
+ final long seed,
+ final long[] hashOut) {
if ((in == null) || (in.length() == 0)) {
throw new IllegalArgumentException("Input in is empty or null.");
}
@@ -168,8 +185,12 @@ public final class MurmurHash3v2 {
* @return the hash.
*/
@SuppressWarnings("restriction")
- public static long[] hash(final Memory mem, final long offsetBytes, final long lengthBytes,
- final long seed, final long[] hashOut) {
+ public static long[] hash(
+ final Memory mem,
+ final long offsetBytes,
+ final long lengthBytes,
+ final long seed,
+ final long[] hashOut) {
if ((mem == null) || (mem.getCapacity() == 0L)) {
throw new IllegalArgumentException("Input mem is empty or null.");
}
@@ -338,7 +359,11 @@ public final class MurmurHash3v2 {
* @param hashOut the output array of 2 longs
* @return hashOut
*/
- private static long[] finalMix128(long h1, long h2, final long lengthBytes, final long[] hashOut) {
+ private static long[] finalMix128(
+ long h1,
+ long h2,
+ final long lengthBytes,
+ final long[] hashOut) {
h1 ^= lengthBytes;
h2 ^= lengthBytes;
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Positional.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Positional.java
index 66164af..e746607 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Positional.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Positional.java
@@ -102,6 +102,9 @@ public interface Positional extends Resource {
* @return BaseBuffer
* @throws BufferPositionInvariantsException if positional invariants have been violated.
*/
- Positional setStartPositionEnd(long start, long position, long end);
+ Positional setStartPositionEnd(
+ long start,
+ long position,
+ long end);
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Resource.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Resource.java
index 26c6717..269ceb7 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Resource.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Resource.java
@@ -129,7 +129,11 @@ public interface Resource extends AutoCloseable {
* @throws IllegalStateException if either resource is not <em>alive</em>.
* @throws MemoryBoundsException if there is a bounds violation.
*/
- boolean equalTo(long thisOffsetBytes, Resource that, long thatOffsetBytes, long lengthBytes);
+ boolean equalTo(
+ long thisOffsetBytes,
+ Resource that,
+ long thatOffsetBytes,
+ long lengthBytes);
/**
* Forces any changes made to the contents of this memory-mapped Resource to be written to the storage
@@ -337,7 +341,11 @@ public interface Resource extends AutoCloseable {
* @param withData include output listing of byte data in the given range
* @return a formatted hex string in a human readable array
*/
- String toString(String header, long offsetBytes, int lengthBytes, boolean withData);
+ String toString(
+ String header,
+ long offsetBytes,
+ int lengthBytes,
+ boolean withData);
/**
* Returns a brief description of this object.
@@ -357,7 +365,10 @@ public interface Resource extends AutoCloseable {
* @return the 64-bit hash of the sequence of bytes in this object specified by
* <i>offsetBytes</i> and <i>lengthBytes</i>.
*/
- long xxHash64(long offsetBytes, long lengthBytes, long seed);
+ long xxHash64(
+ long offsetBytes,
+ long lengthBytes,
+ long seed);
/**
* Returns a 64-bit hash from a single long. This method has been optimized for speed when only
@@ -366,6 +377,8 @@ public interface Resource extends AutoCloseable {
* @param seed A long valued seed.
* @return the hash.
*/
- long xxHash64(long in, long seed);
+ long xxHash64(
+ long in,
+ long seed);
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableBuffer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableBuffer.java
index 59ba545..99b8858 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableBuffer.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableBuffer.java
@@ -59,7 +59,10 @@ public interface WritableBuffer extends Buffer {
* @return a new <i>WritableBuffer</i> for write operations on the given <i>ByteBuffer</i>.
* @throws IllegalArgumentException if ByteBuffer is not writable
*/
- static WritableBuffer writableWrap(ByteBuffer byteBuffer, ByteOrder byteOrder, MemoryRequestServer memReqSvr) {
+ static WritableBuffer writableWrap(
+ ByteBuffer byteBuffer,
+ ByteOrder byteOrder,
+ MemoryRequestServer memReqSvr) {
if (byteBuffer.isReadOnly()) {
throw new ReadOnlyException("Cannot create a WritableBuffer from a ReadOnly ByteBuffer.");
}
@@ -142,7 +145,10 @@ public interface WritableBuffer extends Buffer {
* @return a new <i>WritableBuffer</i> representing the defined writable region
* with the given offsetBytes, capacityBytes and byte order.
*/
- WritableBuffer writableRegion(long offsetBytes, long capacityBytes, ByteOrder byteOrder);
+ WritableBuffer writableRegion(
+ long offsetBytes,
+ long capacityBytes,
+ ByteOrder byteOrder);
//AS WRITABLE MEMORY
/**
@@ -184,7 +190,9 @@ public interface WritableBuffer extends Buffer {
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start.
* @param value the value to put
*/
- void putBoolean(long offsetBytes, boolean value);
+ void putBoolean(
+ long offsetBytes,
+ boolean value);
/**
* Puts the byte value at the current position.
@@ -199,7 +207,9 @@ public interface WritableBuffer extends Buffer {
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- void putByte(long offsetBytes, byte value);
+ void putByte(
+ long offsetBytes,
+ byte value);
/**
* Puts the byte array at the current position.
@@ -208,7 +218,10 @@ public interface WritableBuffer extends Buffer {
* @param srcOffsetBytes offset in array units
* @param lengthBytes number of array units to transfer
*/
- void putByteArray(byte[] srcArray, int srcOffsetBytes, int lengthBytes);
+ void putByteArray(
+ byte[] srcArray,
+ int srcOffsetBytes,
+ int lengthBytes);
/**
* Puts the char value at the current position.
@@ -223,7 +236,9 @@ public interface WritableBuffer extends Buffer {
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- void putChar(long offsetBytes, char value);
+ void putChar(
+ long offsetBytes,
+ char value);
/**
* Puts the char array at the current position.
@@ -232,7 +247,10 @@ public interface WritableBuffer extends Buffer {
* @param srcOffsetChars offset in array units
* @param lengthChars number of array units to transfer
*/
- void putCharArray(char[] srcArray, int srcOffsetChars, int lengthChars);
+ void putCharArray(
+ char[] srcArray,
+ int srcOffsetChars,
+ int lengthChars);
/**
* Puts the double value at the current position.
@@ -247,7 +265,9 @@ public interface WritableBuffer extends Buffer {
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- void putDouble(long offsetBytes, double value);
+ void putDouble(
+ long offsetBytes,
+ double value);
/**
* Puts the double array at the current position.
@@ -256,7 +276,10 @@ public interface WritableBuffer extends Buffer {
* @param srcOffsetDoubles offset in array units
* @param lengthDoubles number of array units to transfer
*/
- void putDoubleArray(double[] srcArray, int srcOffsetDoubles, int lengthDoubles);
+ void putDoubleArray(
+ double[] srcArray,
+ int srcOffsetDoubles,
+ int lengthDoubles);
/**
* Puts the float value at the current position.
@@ -271,7 +294,9 @@ public interface WritableBuffer extends Buffer {
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- void putFloat(long offsetBytes, float value);
+ void putFloat(
+ long offsetBytes,
+ float value);
/**
* Puts the float array at the current position.
@@ -280,7 +305,10 @@ public interface WritableBuffer extends Buffer {
* @param srcOffsetFloats offset in array units
* @param lengthFloats number of array units to transfer
*/
- void putFloatArray(float[] srcArray, int srcOffsetFloats, int lengthFloats);
+ void putFloatArray(
+ float[] srcArray,
+ int srcOffsetFloats,
+ int lengthFloats);
/**
* Puts the int value at the current position.
@@ -295,7 +323,9 @@ public interface WritableBuffer extends Buffer {
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- void putInt(long offsetBytes, int value);
+ void putInt(
+ long offsetBytes,
+ int value);
/**
* Puts the int array at the current position.
@@ -304,7 +334,10 @@ public interface WritableBuffer extends Buffer {
* @param srcOffsetInts offset in array units
* @param lengthInts number of array units to transfer
*/
- void putIntArray(int[] srcArray, int srcOffsetInts, int lengthInts);
+ void putIntArray(
+ int[] srcArray,
+ int srcOffsetInts,
+ int lengthInts);
/**
* Puts the long value at the current position.
@@ -319,7 +352,9 @@ public interface WritableBuffer extends Buffer {
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- void putLong(long offsetBytes, long value);
+ void putLong(
+ long offsetBytes,
+ long value);
/**
* Puts the long array at the current position.
@@ -328,7 +363,10 @@ public interface WritableBuffer extends Buffer {
* @param srcOffsetLongs offset in array units
* @param lengthLongs number of array units to transfer
*/
- void putLongArray(long[] srcArray, int srcOffsetLongs, int lengthLongs);
+ void putLongArray(
+ long[] srcArray,
+ int srcOffsetLongs,
+ int lengthLongs);
/**
* Puts the short value at the current position.
@@ -343,7 +381,9 @@ public interface WritableBuffer extends Buffer {
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- void putShort(long offsetBytes, short value);
+ void putShort(
+ long offsetBytes,
+ short value);
/**
* Puts the short array at the current position.
@@ -352,7 +392,10 @@ public interface WritableBuffer extends Buffer {
* @param srcOffsetShorts offset in array units
* @param lengthShorts number of array units to transfer
*/
- void putShortArray(short[] srcArray, int srcOffsetShorts, int lengthShorts);
+ void putShortArray(
+ short[] srcArray,
+ int srcOffsetShorts,
+ int lengthShorts);
// NO ATOMIC METHODS
@@ -361,7 +404,7 @@ public interface WritableBuffer extends Buffer {
* Returns the primitive backing array, otherwise null.
* @return the primitive backing array, otherwise null.
*/
- byte[] getArray();
+ Object getArray();
/**
* Clears all bytes of this Buffer from position to end to zero. The position will be set to end.
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java
index 930df0c..d48d3db 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java
@@ -29,7 +29,6 @@ import java.util.Objects;
import org.apache.datasketches.memory.internal.BaseWritableMemoryImpl;
import org.apache.datasketches.memory.internal.Prim;
-import org.apache.datasketches.memory.internal.ResourceImpl;
/**
* Defines the writable API for offset access to a resource.
@@ -331,8 +330,6 @@ public interface WritableMemory extends Memory {
int lengthBytes,
ByteOrder byteOrder,
MemoryRequestServer memReqSvr) {
- Objects.requireNonNull(array, "array must be non-null");
- ResourceImpl.checkBounds(offsetBytes, lengthBytes, array.length);
return BaseWritableMemoryImpl.wrapHeapArray(array, offsetBytes, lengthBytes, false, byteOrder, memReqSvr);
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/XxHash.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/XxHash.java
index 9be0522..281f340 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/XxHash.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/XxHash.java
@@ -59,8 +59,11 @@ public final class XxHash {
* @param seed the given seed
* @return the hash
*/
- public static long hashByteArr(final byte[] arr, final long offsetBytes,
- final long lengthBytes, final long seed) {
+ public static long hashByteArr(
+ final byte[] arr,
+ final long offsetBytes,
+ final long lengthBytes,
+ final long seed) {
return hashBytes(arr, offsetBytes, lengthBytes, seed);
}
@@ -73,8 +76,11 @@ public final class XxHash {
* @param seed the given seed
* @return the hash
*/
- public static long hashShortArr(final short[] arr, final long offsetShorts,
- final long lengthShorts, final long seed) {
+ public static long hashShortArr(
+ final short[] arr,
+ final long offsetShorts,
+ final long lengthShorts,
+ final long seed) {
return hashShorts(arr, offsetShorts, lengthShorts, seed);
}
@@ -87,8 +93,11 @@ public final class XxHash {
* @param seed the given seed
* @return the hash
*/
- public static long hashCharArr(final char[] arr, final long offsetChars,
- final long lengthChars, final long seed) {
+ public static long hashCharArr(
+ final char[] arr,
+ final long offsetChars,
+ final long lengthChars,
+ final long seed) {
return hashChars(arr, offsetChars, lengthChars, seed);
}
@@ -101,8 +110,11 @@ public final class XxHash {
* @param seed the given seed
* @return the hash
*/
- public static long hashIntArr(final int[] arr, final long offsetInts,
- final long lengthInts, final long seed) {
+ public static long hashIntArr(
+ final int[] arr,
+ final long offsetInts,
+ final long lengthInts,
+ final long seed) {
return hashInts(arr, offsetInts, lengthInts, seed);
}
@@ -115,8 +127,11 @@ public final class XxHash {
* @param seed the given seed
* @return the hash
*/
- public static long hashLongArr(final long[] arr, final long offsetLongs,
- final long lengthLongs, final long seed) {
+ public static long hashLongArr(
+ final long[] arr,
+ final long offsetLongs,
+ final long lengthLongs,
+ final long seed) {
return hashLongs(arr, offsetLongs, lengthLongs, seed);
}
@@ -127,7 +142,9 @@ public final class XxHash {
* @param seed A long valued seed.
* @return the hash.
*/
- public static long hashLong(final long in, final long seed) {
+ public static long hashLong(
+ final long in,
+ final long seed) {
return hash(in, seed);
}
@@ -140,8 +157,11 @@ public final class XxHash {
* @param seed the given seed
* @return the hash
*/
- public static long hashFloatArr(final float[] arr, final long offsetFloats,
- final long lengthFloats, final long seed) {
+ public static long hashFloatArr(
+ final float[] arr,
+ final long offsetFloats,
+ final long lengthFloats,
+ final long seed) {
return hashFloats(arr, offsetFloats, lengthFloats, seed);
}
@@ -154,8 +174,11 @@ public final class XxHash {
* @param seed the given seed
* @return the hash
*/
- public static long hashDoubleArr(final double[] arr, final long offsetDoubles,
- final long lengthDoubles, final long seed) {
+ public static long hashDoubleArr(
+ final double[] arr,
+ final long offsetDoubles,
+ final long lengthDoubles,
+ final long seed) {
return hashDoubles(arr, offsetDoubles, lengthDoubles, seed);
}
@@ -168,10 +191,12 @@ public final class XxHash {
* @param seed the given seed
* @return the hash
*/
- public static long hashString(final String str, final long offsetChars,
- final long lengthChars, final long seed) {
+ public static long hashString(
+ final String str,
+ final long offsetChars,
+ final long lengthChars,
+ final long seed) {
return org.apache.datasketches.memory.internal.XxHash64.hashString(str, offsetChars, lengthChars, seed);
}
}
-
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
index 0511286..86fbe03 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
@@ -365,9 +365,9 @@ public abstract class BaseWritableBufferImpl extends PositionalImpl implements W
* @return the primitive backing array, otherwise null.
*/
@Override
- public final byte[] getArray() {
+ public final Object getArray() {
checkValid();
- return (byte[])getUnsafeObject();
+ return getUnsafeObject();
}
@Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
index 35592cd..5bee6e7 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
@@ -76,6 +76,9 @@ public abstract class BaseWritableMemoryImpl extends ResourceImpl implements Wri
Util.negativeCheck(offsetBytes, "offsetBytes");
Util.negativeCheck(lengthBytes, "lengthBytes");
Objects.requireNonNull(byteOrder, "byteOrder must be non-null");
+ if (array instanceof byte[]) {
+ ResourceImpl.checkBounds(offsetBytes, lengthBytes, ((byte[])array).length);
+ }
final long cumOffsetBytes = UnsafeUtil.getArrayBaseOffset(array.getClass()) + offsetBytes;
final int typeId = (localReadOnly ? READONLY : 0);
return Util.isNativeByteOrder(byteOrder)
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java
index d214582..f73f268 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java
@@ -260,8 +260,7 @@ public abstract class ResourceImpl implements Resource {
return typeId;
}
- //Overridden by Heap and ByteBuffer leaves. Made public as getArray() in WritableMemoryImpl and
- // WritableBufferImpl
+ //Overridden by Heap and ByteBuffer leaves. Made public as getArray() in BaseWritableMemoryImpl and BaseWritableBufferImpl
Object getUnsafeObject() {
return null;
}
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/IsValidUtf8TestUtil.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/IsValidUtf8TestUtil.java
deleted file mode 100644
index cf01920..0000000
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/IsValidUtf8TestUtil.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.datasketches.memory.internal;
-
-/**
- * Stripped down version of
- * https://github.com/protocolbuffers/protobuf/blob/master/java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java
- *
- * <p>Copyright 2008 Google Inc. All rights reserved.
- * https://developers.google.com/protocol-buffers/
- * See LICENSE.
- */
-public class IsValidUtf8TestUtil {
-
- // 128 - [chars 0x0000 to 0x007f]
- static final long ONE_BYTE_ROUNDTRIPPABLE_CHARACTERS = (0x007f - 0x0000) + 1;
-
- // 128
- static final long EXPECTED_ONE_BYTE_ROUNDTRIPPABLE_COUNT = ONE_BYTE_ROUNDTRIPPABLE_CHARACTERS;
-
- // 1920 [chars 0x0080 to 0x07FF]
- static final long TWO_BYTE_ROUNDTRIPPABLE_CHARACTERS = (0x07FF - 0x0080) + 1;
-
- // 18,304
- static final long EXPECTED_TWO_BYTE_ROUNDTRIPPABLE_COUNT =
- // Both bytes are one byte characters
- (long) Math.pow(EXPECTED_ONE_BYTE_ROUNDTRIPPABLE_COUNT, 2)
- // The possible number of two byte characters
- + TWO_BYTE_ROUNDTRIPPABLE_CHARACTERS;
-
- // 2048
- static final long THREE_BYTE_SURROGATES = 2 * 1024;
-
- // 61,440 [chars 0x0800 to 0xFFFF, minus surrogates]
- static final long THREE_BYTE_ROUNDTRIPPABLE_CHARACTERS =
- ((0xFFFF - 0x0800) + 1) - THREE_BYTE_SURROGATES;
-
- // 2,650,112
- static final long EXPECTED_THREE_BYTE_ROUNDTRIPPABLE_COUNT =
- // All one byte characters
- (long) Math.pow(EXPECTED_ONE_BYTE_ROUNDTRIPPABLE_COUNT, 3)
- // One two byte character and a one byte character
- + (2 * TWO_BYTE_ROUNDTRIPPABLE_CHARACTERS * ONE_BYTE_ROUNDTRIPPABLE_CHARACTERS)
- // Three byte characters
- + THREE_BYTE_ROUNDTRIPPABLE_CHARACTERS;
-
-}
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
index 6a75c0f..aacdba4 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
@@ -35,6 +35,7 @@ import java.util.List;
import org.apache.datasketches.memory.DefaultMemoryRequestServer;
import org.apache.datasketches.memory.Memory;
+import org.apache.datasketches.memory.MemoryBoundsException;
import org.apache.datasketches.memory.MemoryRequestServer;
import org.apache.datasketches.memory.Resource;
import org.apache.datasketches.memory.WritableBuffer;
@@ -406,6 +407,30 @@ public class MemoryTest {
}
}
+ @Test
+ public void checkArrayBounds() {
+ byte[] arr = new byte[100];
+ int offset = 50;
+ int len = 51;
+ for (int i = 0; i < 100; i++) { arr[i] = (byte)(i + 1); }
+ try { //this worked
+ Memory.wrap(arr, offset, len, ByteOrder.LITTLE_ENDIAN);
+ } catch (MemoryBoundsException e) { }
+ try { //this was a bug
+ BaseWritableMemoryImpl.wrapHeapArray(arr, offset, len, false, ByteOrder.LITTLE_ENDIAN, null);
+ } catch (MemoryBoundsException e) { }
+ }
+
+ @Test
+ public void checkByteOrder() {
+ byte[] arr = new byte[4];
+ int test = 1;
+ arr[0] = (byte)test;
+ Memory mem = Memory.wrap(arr, ByteOrder.BIG_ENDIAN);
+ int t = mem.getInt(0);
+ assertEquals(t, Integer.reverseBytes(test));
+ }
+
@Test
public void printlnTest() {
println("PRINTING: " + this.getClass().getName());
diff --git a/pom.xml b/pom.xml
index 1a5c746..f830b4c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
-
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -18,7 +17,6 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -27,7 +25,6 @@ under the License.
<groupId>org.apache.datasketches</groupId>
<artifactId>datasketches-memory-root</artifactId>
<version>3.0.0-SNAPSHOT</version>
- <!-- Required for multi-module project -->
<packaging>pom</packaging>
<name>${project.artifactId}</name>
@@ -60,8 +57,8 @@ under the License.
</scm>
<issueManagement>
- <!-- <system>jira</system>
- <url>https://issues.apache.org/jira/browse/DATASKETCHES</url> -->
+ <!-- <system>jira</system> -->
+ <!-- <url>https://issues.apache.org/jira/browse/DATASKETCHES</url> -->
<system>GitHub</system>
<url>https://github.com/apache/${project.artifactId}/issues</url>
</issueManagement>
@@ -77,7 +74,7 @@ under the License.
</developers>
<!--
- NOTE:
+ NOTICE:
The datasketches-memory submodule uses the Maven project-aggregation feature and does not inherit
from this root module as a parent; so that there is no runtime dependency on the parent project (root module).
As a result, some properties from this POM (including the version) are duplicated in the datasketches-memory
@@ -86,16 +83,15 @@ under the License.
<properties>
- <protobuf-java.version>4.0.0-rc-2</protobuf-java.version>
- <!-- Used for UTF8 testing -->
- <zero-allocation-hashing.version>0.15</zero-allocation-hashing.version>
+ <!-- Used for xxHash testing -->
+ <zero-allocation-hashing.version>0.16</zero-allocation-hashing.version>
<!-- Test -->
<testng.version>7.5.1</testng.version>
<!-- System-wide properties -->
- <maven.version>3.5.0</maven.version>
- <java.version>1.8</java.version>
+ <maven.version>3.6.3</maven.version>
+ <java.version>8</java.version>
<jdk-toolchain.version>8</jdk-toolchain.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
@@ -106,33 +102,34 @@ under the License.
<project.reporting.outputEncoding>${charset.encoding}</project.reporting.outputEncoding>
<!-- org.codehaus plugins -->
- <!-- used for strict profile testing-->
- <plexus-compiler-javac-errorprone.version>2.8.5</plexus-compiler-javac-errorprone.version>
- <versions-maven-plugin.version>2.8.1</versions-maven-plugin.version>
+ <versions-maven-plugin.version>2.16.2</versions-maven-plugin.version>
+ <exec-maven-plugin.version>3.3.0</exec-maven-plugin.version>
<!-- Maven Plugins -->
- <maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
- <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
- <maven-deploy-plugin.version>3.0.0-M1</maven-deploy-plugin.version>
- <maven-enforcer-plugin.version>3.0.0</maven-enforcer-plugin.version>
- <maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
- <maven-javadoc-plugin.version>3.3.1</maven-javadoc-plugin.version>
- <maven-release-plugin.version>3.0.0-M4</maven-release-plugin.version>
- <maven-remote-resources-plugin.version>1.7.0</maven-remote-resources-plugin.version>
- <maven-source-plugin.version>3.2.1</maven-source-plugin.version>
- <maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
- <maven-toolchains-plugin.version>3.0.0</maven-toolchains-plugin.version>
+ <maven-assembly-plugin.version>3.7.1</maven-assembly-plugin.version>
+ <maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
+ <maven-deploy-plugin.version>3.1.2</maven-deploy-plugin.version>
+ <maven-enforcer-plugin.version>3.4.1</maven-enforcer-plugin.version>
+ <maven-gpg-plugin.version>3.2.3</maven-gpg-plugin.version>
+ <maven-jar-plugin.version>3.4.1</maven-jar-plugin.version>
+ <maven-javadoc-plugin.version>3.6.3</maven-javadoc-plugin.version>
+ <maven-release-plugin.version>3.0.1</maven-release-plugin.version>
+ <maven-remote-resources-plugin.version>3.2.0</maven-remote-resources-plugin.version>
+ <maven-source-plugin.version>3.3.1</maven-source-plugin.version>
+ <maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version> <!-- for surefire, failsafe and surefire-report -->
+ <maven-toolchains-plugin.version>3.2.0</maven-toolchains-plugin.version>
<maven-install-plugin.version>3.0.0-M1</maven-install-plugin.version>
- <maven-exec-plugin.version>3.0.0</maven-exec-plugin.version>
<!-- Apache Plugins -->
- <apache-rat-plugin.version>0.13</apache-rat-plugin.version>
+ <apache-rat-plugin.version>0.16.1</apache-rat-plugin.version>
<!-- org.jacoco Maven Plugins -->
- <jacoco-maven-plugin.version>0.8.6</jacoco-maven-plugin.version>
+ <jacoco-maven-plugin.version>0.8.12</jacoco-maven-plugin.version>
<!-- org.eluder Maven Plugins -->
<coveralls-repo-token></coveralls-repo-token>
<coveralls-maven-plugin.version>4.3.0</coveralls-maven-plugin.version>
<!-- other -->
<lifecycle-mapping.version>1.0.0</lifecycle-mapping.version>
+ <git-commit-id-plugin.version>4.9.10</git-commit-id-plugin.version>
+ <exec-maven-plugin.version>3.3.0</exec-maven-plugin.version>
<maven.deploy.skip>true</maven.deploy.skip>
<maven.install.skip>true</maven.install.skip>
<maven.javadoc.skip>true</maven.javadoc.skip>
@@ -207,14 +204,12 @@ under the License.
</plugin>
<plugin>
- <!-- Apache Parent pom, pluginManagement-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>${maven-release-plugin.version}</version>
</plugin>
<plugin>
- <!-- Extends Apache Parent pom, pluginManagement-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
@@ -237,7 +232,6 @@ under the License.
</plugin>
<plugin>
- <!-- Extends Apache Parent pom, apache-release profile -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
@@ -273,7 +267,7 @@ under the License.
<configuration>
<rules>
<requireJavaVersion>
- <version>[1.8,1.9),[8],[11,14),[17,18)</version>
+ <version>[8,9),[11,12)</version>
</requireJavaVersion>
<requireMavenVersion>
<version>[${maven.version},)</version>
@@ -292,7 +286,6 @@ under the License.
</plugin>
<plugin>
- <!-- Apache Parent pom, pluginManagement-->
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
<version>${apache-rat-plugin.version}</version>
@@ -311,7 +304,8 @@ under the License.
<excludes>
<exclude>**/*.yaml</exclude>
<exclude>**/*.yml</exclude>
- <exclude>**/.*/**/*</exclude>
+ <exclude>**/toolchains.xml</exclude>
+ <exclude>**/.*</exclude>
<exclude>**/.clover/**/*</exclude>
<exclude>**/test/resources/**/*.txt</exclude>
<exclude>**/test-output/**/*</exclude>
@@ -325,7 +319,6 @@ under the License.
</plugin>
<plugin>
- <!-- Extends Apache Parent pom, apache-release profile -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
@@ -348,7 +341,6 @@ under the License.
</plugin>
<plugin>
- <!-- Apache Parent pom, pluginManagement-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
@@ -370,13 +362,15 @@ under the License.
<configuration>
<toolchains>
<jdk>
- <version>[1.8,1.9),[8],[11,14),[17,18)</version>
+ <version>[8,9),[11,12)</version>
</jdk>
</toolchains>
</configuration>
<executions>
<execution>
- <goals><goal>toolchain</goal></goals>
+ <goals>
+ <goal>toolchain</goal>
+ </goals>
</execution>
</executions>
</plugin>
@@ -423,7 +417,7 @@ under the License.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
- <version>${maven-exec-plugin.version}</version>
+ <version>${exec-maven-plugin.version}</version>
</plugin>
</plugins>
diff --git a/tools/scripts/assets/CheckMemoryJar.java b/tools/scripts/assets/CheckMemoryJar.java
index d369c85..ba16ca4 100644
--- a/tools/scripts/assets/CheckMemoryJar.java
+++ b/tools/scripts/assets/CheckMemoryJar.java
@@ -23,9 +23,7 @@ import java.io.File;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import org.apache.datasketches.memory.MapHandle;
import org.apache.datasketches.memory.Memory;
-import org.apache.datasketches.memory.WritableHandle;
import org.apache.datasketches.memory.WritableMemory;
public class CheckMemoryJar {
@@ -51,10 +49,9 @@ public class CheckMemoryJar {
public void checkAllocateDirect() throws Exception {
try {
String str = "2 - Allocate Direct Successful";
- WritableHandle wh = WritableMemory.allocateDirect(2 * str.length());
- WritableMemory wmem = wh.getWritable();
+ WritableMemory wmem = WritableMemory.allocateDirect(2 * str.length());
writeReadAndPrintString(wmem, str);
- wh.close();
+ wmem.close();
} catch (Exception ex) {
exitOnError("Allocate Direct", ex);
}
@@ -76,9 +73,8 @@ public class CheckMemoryJar {
try {
String str = "4 - Memory Map Successful";
File file = new File(mappedFilePath);
- MapHandle mh = Memory.map(file);
- Memory mem = mh.get();
- mh.close();
+ Memory mem = Memory.map(file);
+ mem.close();
println(str);
} catch (Exception ex) {
exitOnError("Memory Map", ex);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org