Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>zero-allocation-hashing</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
<filteredResources>
<filter>
<id>1774259938529</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
26 changes: 14 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@

-->

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<parent>
<parent>
<groupId>net.openhft</groupId>
<artifactId>java-parent-pom</artifactId>
<version>2026.0</version>
<relativePath />
<relativePath/>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>zero-allocation-hashing</artifactId>
<version>2026.1-SNAPSHOT</version>
<name>Zero-allocation Hashing</name>
<description>Zero-allocation implementations of fast non-cryptographic hash functions
for byte sequences or blocks of memory</description>
for byte sequences or blocks of memory
</description>
<inceptionYear>2014</inceptionYear>
<url>https://github.com/OpenHFT/Zero-Allocation-Hashing</url>
<packaging>bundle</packaging>
Expand Down Expand Up @@ -60,11 +62,10 @@
<!-- test dependencies -->

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.0</version>
<scope>test</scope>
<!-- JUnit 4 supports Java 7, but JUnit 5 don't. -->
</dependency>

<dependency>
Expand Down Expand Up @@ -215,15 +216,16 @@
</executions>
</plugin>


<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M4</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-gitexe</artifactId>
<version>1.11.2</version> <!-- this version should be sync with the scmVersion of maven-release-plugin -->
<version>1.11.2
</version> <!-- this version should be sync with the scmVersion of maven-release-plugin -->
</dependency>
</dependencies>
</plugin>
Expand All @@ -242,7 +244,7 @@
</configuration>
</plugin>

<plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
Expand Down Expand Up @@ -294,7 +296,7 @@
<properties>
<project.jdk.min-version>1.${project.target.release}</project.jdk.min-version>
<maven.bundle.plugin.version>3.5.1</maven.bundle.plugin.version>
<doclint />
<doclint/>
</properties>
</profile>
<profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import java.nio.ByteOrder;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.annotation.ParametersAreNonnullByDefault;

import static java.nio.ByteOrder.BIG_ENDIAN;
import static java.nio.ByteOrder.LITTLE_ENDIAN;
import static net.openhft.hashing.UnsafeAccess.BYTE_BASE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import java.lang.reflect.Field;
import javax.annotation.ParametersAreNonnullByDefault;
import static net.openhft.hashing.UnsafeAccess.*;

import static net.openhft.hashing.Util.*;

@ParametersAreNonnullByDefault
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/net/openhft/hashing/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import org.jetbrains.annotations.NotNull;

import static java.nio.ByteOrder.*;

final class Util {

/* Known java.vm.name list:
Expand Down
18 changes: 9 additions & 9 deletions src/test/java/net/openhft/hashing/ByteBufferAccessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
*/
package net.openhft.hashing;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import static java.nio.ByteOrder.BIG_ENDIAN;
import static java.nio.ByteOrder.LITTLE_ENDIAN;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;

public class ByteBufferAccessTest {
class ByteBufferAccessTest {

private static final byte[] SAMPLE = {
(byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
(byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0
};

@Test
public void littleEndianAccessReadsExpectedValues() {
void littleEndianAccessReadsExpectedValues() {
ByteBuffer buffer = ByteBuffer.wrap(SAMPLE).order(LITTLE_ENDIAN);
ByteBufferAccess access = ByteBufferAccess.INSTANCE;

assertEquals(ByteOrder.LITTLE_ENDIAN, access.byteOrder(buffer));
assertSame(ByteOrder.LITTLE_ENDIAN, access.byteOrder(buffer));
assertEquals(0xF0DEBC9A78563412L, access.getLong(buffer, 0));
assertEquals(0xF0DEBC9AL, access.getUnsignedInt(buffer, 4));
assertEquals(0x78563412, access.getInt(buffer, 0));
Expand All @@ -35,11 +35,11 @@ public void littleEndianAccessReadsExpectedValues() {
}

@Test
public void bigEndianAccessReadsExpectedValues() {
void bigEndianAccessReadsExpectedValues() {
ByteBuffer buffer = ByteBuffer.wrap(SAMPLE).order(BIG_ENDIAN);
ByteBufferAccess access = ByteBufferAccess.INSTANCE;

assertEquals(ByteOrder.BIG_ENDIAN, access.byteOrder(buffer));
assertSame(ByteOrder.BIG_ENDIAN, access.byteOrder(buffer));
assertEquals(0x123456789ABCDEF0L, access.getLong(buffer, 0));
assertEquals(0x12345678L, access.getUnsignedInt(buffer, 0));
assertEquals((int) 0x9ABCDEF0L, access.getInt(buffer, 4));
Expand All @@ -50,11 +50,11 @@ public void bigEndianAccessReadsExpectedValues() {
}

@Test
public void reverseAccessFlipsByteOrder() {
void reverseAccessFlipsByteOrder() {
ByteBuffer buffer = ByteBuffer.wrap(SAMPLE).order(LITTLE_ENDIAN);
Access<ByteBuffer> reverse = ByteBufferAccess.INSTANCE.reverseAccess();

assertEquals(ByteOrder.BIG_ENDIAN, reverse.byteOrder(buffer));
assertSame(ByteOrder.BIG_ENDIAN, reverse.byteOrder(buffer));
assertEquals(0x123456789ABCDEF0L, reverse.getLong(buffer, 0));
assertEquals(0x12345678L, reverse.getUnsignedInt(buffer, 0));
assertEquals((int) 0x9ABCDEF0L, reverse.getInt(buffer, 4));
Expand Down
92 changes: 45 additions & 47 deletions src/test/java/net/openhft/hashing/CharSequenceAccessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@
*/
package net.openhft.hashing;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assume.assumeTrue;
import static java.nio.ByteOrder.*;
import static net.openhft.hashing.Primitives.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.*;

public class CharSequenceAccessTest {
static String TEST_STRING = new String(new char[] {0xF0E1,0xD2C3,0xB4A5,0x9687,0xC8E9});
class CharSequenceAccessTest {
static String TEST_STRING = new String(new char[]{0xF0E1, 0xD2C3, 0xB4A5, 0x9687, 0xC8E9});

@Test
public void testInstanceLE() {
void testInstanceLE() {
assumeTrue(nativeOrder() == LITTLE_ENDIAN);

final Access<CharSequence> nativeAccess = CharSequenceAccess.nativeCharSequenceAccess();
Expand All @@ -26,7 +24,7 @@
}

@Test
public void testInstanceBE() {
void testInstanceBE() {
assumeTrue(nativeOrder() == BIG_ENDIAN);

final Access<CharSequence> nativeAccess = CharSequenceAccess.nativeCharSequenceAccess();
Expand All @@ -36,7 +34,7 @@
}

@Test
public void testInstanceReverse() {
void testInstanceReverse() {
Access<CharSequence> access = CharSequenceAccess.charSequenceAccess(BIG_ENDIAN);
assertSame(access, access.reverseAccess().reverseAccess());
assertNotSame(access.byteOrder(null), access.reverseAccess().byteOrder(null));
Expand All @@ -51,67 +49,67 @@
}

@Test
public void testLittleEndian() {
void testLittleEndian() {

Check warning on line 52 in src/test/java/net/openhft/hashing/CharSequenceAccessTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce the number of assertions from 28 to less than 25.

See more on https://sonarcloud.io/project/issues?id=OpenHFT_Zero-Allocation-Hashing&issues=AZ0ppPxn2BMkbzG0LxqQ&open=AZ0ppPxn2BMkbzG0LxqQ&pullRequest=108
// This case works on both little- and big- endians.

final Access<CharSequence> access = CharSequenceAccess.charSequenceAccess(LITTLE_ENDIAN);
final Access<CharSequence> accessR = access.reverseAccess();

assertEquals( 0x9687B4A5D2C3F0E1L, access.getLong(TEST_STRING, 0));
assertEquals(0xE99687B4A5D2C3F0L , access.getLong(TEST_STRING, 1));
assertEquals(0xE1F0C3D2A5B48796L , accessR.getLong(TEST_STRING, 0));
assertEquals( 0xF0C3D2A5B48796E9L, accessR.getLong(TEST_STRING, 1));

assertEquals(unsignedInt( 0xD2C3F0E1), access.getUnsignedInt(TEST_STRING, 0));
assertEquals(unsignedInt(0xA5D2C3F0 ), access.getUnsignedInt(TEST_STRING, 1));
assertEquals( 0xD2C3F0E1, access.getInt(TEST_STRING, 0));
assertEquals(0xA5D2C3F0 , access.getInt(TEST_STRING, 1));
assertEquals(unsignedInt(0xE1F0C3D2) , accessR.getUnsignedInt(TEST_STRING, 0));
assertEquals(unsignedInt( 0xF0C3D2A5), accessR.getUnsignedInt(TEST_STRING, 1));
assertEquals(0xE1F0C3D2 , accessR.getInt(TEST_STRING, 0));
assertEquals( 0xF0C3D2A5, accessR.getInt(TEST_STRING, 1));

assertEquals(unsignedShort( 0xF0E1), access.getUnsignedShort(TEST_STRING, 0));
assertEquals(unsignedShort(0xC3F0 ), access.getUnsignedShort(TEST_STRING, 1));
assertEquals((int)(short) 0xF0E1, access.getShort(TEST_STRING, 0));
assertEquals((int)(short)0xC3F0 , access.getShort(TEST_STRING, 1));
assertEquals(unsignedShort(0xE1F0 ), accessR.getUnsignedShort(TEST_STRING, 0));
assertEquals(unsignedShort( 0xF0C3), accessR.getUnsignedShort(TEST_STRING, 1));
assertEquals((int)(short)0xE1F0 , accessR.getShort(TEST_STRING, 0));
assertEquals((int)(short) 0xF0C3, accessR.getShort(TEST_STRING, 1));
assertEquals(0x9687B4A5D2C3F0E1L, access.getLong(TEST_STRING, 0));
assertEquals(0xE99687B4A5D2C3F0L, access.getLong(TEST_STRING, 1));
assertEquals(0xE1F0C3D2A5B48796L, accessR.getLong(TEST_STRING, 0));
assertEquals(0xF0C3D2A5B48796E9L, accessR.getLong(TEST_STRING, 1));

assertEquals(unsignedInt(0xD2C3F0E1), access.getUnsignedInt(TEST_STRING, 0));
assertEquals(unsignedInt(0xA5D2C3F0), access.getUnsignedInt(TEST_STRING, 1));
assertEquals(0xD2C3F0E1, access.getInt(TEST_STRING, 0));
assertEquals(0xA5D2C3F0, access.getInt(TEST_STRING, 1));
assertEquals(unsignedInt(0xE1F0C3D2), accessR.getUnsignedInt(TEST_STRING, 0));
assertEquals(unsignedInt(0xF0C3D2A5), accessR.getUnsignedInt(TEST_STRING, 1));
assertEquals(0xE1F0C3D2, accessR.getInt(TEST_STRING, 0));
assertEquals(0xF0C3D2A5, accessR.getInt(TEST_STRING, 1));

assertEquals(unsignedShort(0xF0E1), access.getUnsignedShort(TEST_STRING, 0));
assertEquals(unsignedShort(0xC3F0), access.getUnsignedShort(TEST_STRING, 1));
assertEquals((int) (short) 0xF0E1, access.getShort(TEST_STRING, 0));
assertEquals((int) (short) 0xC3F0, access.getShort(TEST_STRING, 1));
assertEquals(unsignedShort(0xE1F0), accessR.getUnsignedShort(TEST_STRING, 0));
assertEquals(unsignedShort(0xF0C3), accessR.getUnsignedShort(TEST_STRING, 1));
assertEquals((int) (short) 0xE1F0, accessR.getShort(TEST_STRING, 0));
assertEquals((int) (short) 0xF0C3, accessR.getShort(TEST_STRING, 1));

assertEquals(unsignedByte(0xE1), access.getUnsignedByte(TEST_STRING, 0));
assertEquals(unsignedByte(0xF0), access.getUnsignedByte(TEST_STRING, 1));
assertEquals((int)(byte)0xE1, access.getByte(TEST_STRING, 0));
assertEquals((int)(byte)0xF0, access.getByte(TEST_STRING, 1));
assertEquals((int) (byte) 0xE1, access.getByte(TEST_STRING, 0));
assertEquals((int) (byte) 0xF0, access.getByte(TEST_STRING, 1));
assertEquals(unsignedByte(0xE1), accessR.getUnsignedByte(TEST_STRING, 0));
assertEquals(unsignedByte(0xF0), accessR.getUnsignedByte(TEST_STRING, 1));
assertEquals((int)(byte)0xE1, accessR.getByte(TEST_STRING, 0));
assertEquals((int)(byte)0xF0, accessR.getByte(TEST_STRING, 1));
assertEquals((int) (byte) 0xE1, accessR.getByte(TEST_STRING, 0));
assertEquals((int) (byte) 0xF0, accessR.getByte(TEST_STRING, 1));
}

@Test
public void testBigEndian() {
void testBigEndian() {
// This case works on both little- and big- endians.

final Access<CharSequence> access = CharSequenceAccess.charSequenceAccess(BIG_ENDIAN);

assertEquals(0xF0E1D2C3B4A59687L , access.getLong(TEST_STRING, 0));
assertEquals( 0xE1D2C3B4A59687C8L, access.getLong(TEST_STRING, 1));
assertEquals(0xF0E1D2C3B4A59687L, access.getLong(TEST_STRING, 0));
assertEquals(0xE1D2C3B4A59687C8L, access.getLong(TEST_STRING, 1));

assertEquals(unsignedInt(0xF0E1D2C3), access.getUnsignedInt(TEST_STRING, 0));
assertEquals(unsignedInt( 0xE1D2C3B4), access.getUnsignedInt(TEST_STRING, 1));
assertEquals(unsignedInt(0xE1D2C3B4), access.getUnsignedInt(TEST_STRING, 1));
assertEquals(0xF0E1D2C3, access.getInt(TEST_STRING, 0));
assertEquals( 0xE1D2C3B4, access.getInt(TEST_STRING, 1));
assertEquals(0xE1D2C3B4, access.getInt(TEST_STRING, 1));

assertEquals(unsignedShort(0xF0E1), access.getUnsignedShort(TEST_STRING, 0));
assertEquals(unsignedShort( 0xE1D2), access.getUnsignedShort(TEST_STRING, 1));
assertEquals((int)(short)0xF0E1, access.getShort(TEST_STRING, 0));
assertEquals((int)(short) 0xE1D2, access.getShort(TEST_STRING, 1));
assertEquals(unsignedShort(0xE1D2), access.getUnsignedShort(TEST_STRING, 1));
assertEquals((int) (short) 0xF0E1, access.getShort(TEST_STRING, 0));
assertEquals((int) (short) 0xE1D2, access.getShort(TEST_STRING, 1));

assertEquals(unsignedByte(0xF0), access.getUnsignedByte(TEST_STRING, 0));
assertEquals(unsignedByte(0xE1), access.getUnsignedByte(TEST_STRING, 1));
assertEquals((int)(byte)0xF0, access.getByte(TEST_STRING, 0));
assertEquals((int)(byte)0xE1, access.getByte(TEST_STRING, 1));
assertEquals((int) (byte) 0xF0, access.getByte(TEST_STRING, 0));
assertEquals((int) (byte) 0xE1, access.getByte(TEST_STRING, 1));
}
}
Loading
Loading