axhash-map 0.1.5

High-performance HashMap and HashSet backed by hashbrown (SwissTable) and fueled by axhash.
Documentation

axhash-map

High-performance HashMap and HashSet for Rust powered by hashbrown and axhash.

  • SwissTable-based layout via hashbrown
  • AES-accelerated hashing
  • Fast drop-in replacement for standard hash collections
  • Serde-friendly type aliases
  • Deterministic hashing by default

Crates.io Docs.rs License: MIT


Installation

[dependencies]
axhash-map = "0.1"

AES acceleration is selected automatically at runtime.


Usage

Type alias (HashMap / HashSet)

Best for Serde and drop-in compatibility.

use axhash_map::HashMap;

let mut map: HashMap<&str, u32> = HashMap::default();

map.insert("alice", 42);
map.insert("bob", 17);

assert_eq!(map["alice"], 42);

Branded types (AxHashMap / AxHashSet)

Provides convenient constructors like new() and with_capacity().

use axhash_map::AxHashMap;

let mut map: AxHashMap<&str, u32> = AxHashMap::new();

map.insert("fast", 1);

assert_eq!(map.get("fast"), Some(&1));

HashSet

use axhash_map::AxHashSet;

let mut set: AxHashSet<u64> = AxHashSet::new();

set.insert(1);
set.insert(2);
set.insert(2);

assert_eq!(set.len(), 2);
assert!(set.contains(&1));

Constructors

use axhash_map::{
    AxHashMap,
    AxHashSet,
    AxBuildHasher,
};

let map = AxHashMap::<String, i32>::new();

let map =
    AxHashMap::<String, i32>::with_capacity(10_000);

let seed = 0xdeadbeef_cafebabe;

let map: AxHashMap<String, i32, AxBuildHasher> =
    AxHashMap::with_hasher(
        AxBuildHasher::with_seed(seed)
    );

Entry API

use axhash_map::AxHashMap;

let mut map: AxHashMap<&str, u32> = AxHashMap::new();

map.entry("hits")
    .and_modify(|n| *n += 1)
    .or_insert(1);

map.entry("hits")
    .and_modify(|n| *n += 1)
    .or_insert(1);

assert_eq!(map["hits"], 2);

Iterators & Extend

use axhash_map::{AxHashMap, AxHashSet};

let map: AxHashMap<&str, usize> =
    [("a", 1), ("b", 2)]
        .into_iter()
        .collect();

let set: AxHashSet<i32> =
    [1, 2, 3, 2]
        .into_iter()
        .collect();

Raw hashbrown interoperability

use core::hash::BuildHasherDefault;

use axhash_map::{
    AxHashMap,
    RawHashMap,
    AxHasher,
};

let raw: RawHashMap<
    &str,
    u32,
    BuildHasherDefault<AxHasher>
> = RawHashMap::with_hasher(
    BuildHasherDefault::default()
);

let wrapped: AxHashMap<&str, u32> = raw.into();

Custom seed

Use a random seed when handling untrusted external input.

use axhash_map::{AxBuildHasher, AxHashMap};

let seed = 0x1234_5678_9abc_def0;

let map: AxHashMap<
    String,
    String,
    AxBuildHasher
> = AxHashMap::with_hasher(
    AxBuildHasher::with_seed(seed)
);

Links


License

MIT