Java Clean Architecture Masterclass

Java Clean Architecture MasterclassNov 20-21

Join

HashSmith: Fast & memory efficient hash tables for Java

License: MIT Maven Central javadoc Status: experimental

⚠️ This project is experimental and not ready for production use.

HashSmith logo

Overview

Implementations

Why SWAR by default?

Vector API is still incubating, and profiling on my setup showed the SIMD path taking longer than expected, so the default SwissMap favors a SWAR probe. Numbers can differ significantly by hardware/JVM version; please run your own benchmarks if you plan to use SwissSimdMap.

Blog / Write-up

Quick Start

import io.github.bluuewhale.hashsmith.SwissMap;      // SWAR
import io.github.bluuewhale.hashsmith.SwissSimdMap;  // Vector API
import io.github.bluuewhale.hashsmith.ConcurrentSwissMap;
import io.github.bluuewhale.hashsmith.RobinHoodMap;
import io.github.bluuewhale.hashsmith.SwissSet;

public class Demo {
    public static void main(String[] args) {
        // SwissMap (SWAR)
        var swiss = new SwissMap<String, Integer>();
        swiss.put("a", 1);
        swiss.put("b", 2);
        System.out.println(swiss.get("a")); // 1

        // SwissSimdMap (Vector API incubator)
        var swissSimd = new SwissSimdMap<String, Integer>();
        swissSimd.put("a", 1);
        swissSimd.put("b", 2);
        System.out.println(swissSimd.get("a")); // 1

        // ConcurrentSwissMap (sharded, thread-safe)
        var concurrentSwiss = new ConcurrentSwissMap<String, Integer>();
        concurrentSwiss.put("a", 1);
        concurrentSwiss.put("b", 2);
        System.out.println(concurrentSwiss.get("a")); // 1

        // SwissSet
        var swissSet = new SwissSet<String>();
        swissSet.add("k");
        swissSet.add(null); // nulls allowed
        System.out.println(swissSet.contains("k")); // true
    }
}

Install

dependencies {
    implementation("io.github.bluuewhale:hashsmith:0.1.7")
}
dependencies {
    implementation 'io.github.bluuewhale:hashsmith:0.1.7'
}
<dependency>
  <groupId>io.github.bluuewhale</groupId>
  <artifactId>hashsmith</artifactId>
  <version>0.1.7</version>
</dependency>

Requirements

Build & Test

./gradlew build        # full build
./gradlew test         # JUnit 5 tests

Memory Footprint

Results

Map Set
HashMap Memory Footprint HashSet Memory Footprint

Benchmark (JMH, CPU ns/op)

put hit put miss
CPU: put hit CPU: put miss
get hit get miss
CPU: get hit CPU: get miss

Contributing

  1. Open an issue for bugs/ideas
  2. Work on a feature branch and open a PR
  3. Keep tests/JMH green before submitting

License

Join libs.tech

...and unlock some superpowers

GitHub

We won't share your data with anyone else.