Crates.io | frozen-hashbrown |
lib.rs | frozen-hashbrown |
version | 0.1.0 |
source | src |
created_at | 2023-10-30 13:00:13.751539 |
updated_at | 2023-10-30 13:00:13.751539 |
description | Frozen version of Rust standard library's hashbrown |
homepage | |
repository | https://github.com/tyt2y3/frozen-hashbrown |
max_upload_size | |
id | 1018457 |
size | 21,784 |
Frozen version of Rust standard library's hashbrown.
std::collections::HashMap
into a blobHashMap
HashMap
from coredump
Online
TableLayout
for (K, V)
ctrl
and bucket_mask
calculate_layout_for(buckets)
and calculate the address NonNull<u8>
and Layout
Offline
hashbrown::map::HashMap
for (K, V)
HashMap
in Rust's standard library is a flat hashmap. Meaning it's only backed by a single contiguous piece of memory.Vec<(K, V)>
with an index to assist hash key lookupuse frozen_hashbrown::FrozenHashMap;
use std::collections::HashMap;
let map: HashMap<char, i32> = [('a', 1), ('b', 2), ('c', 3), ('d', 4)]
.into_iter()
.collect();
let snapshot = format!("{map:?}");
let frozen = FrozenHashMap::construct(&map);
std::mem::drop(map);
let frozen: Vec<u8> = frozen.store();
let mut unfrozen = FrozenHashMap::load(&frozen).expect("Failed to load");
let unfrozen = unfrozen
.reconstruct::<char, i32>()
.expect("Failed to reconstruct");
let unfrozen_snapshot = format!("{unfrozen:?}");
// even the "random" iteration order holds
assert_eq!(snapshot, unfrozen_snapshot);
More examples under https://github.com/tyt2y3/frozen-hashbrown/blob/main/tests/unfreeze.rs
License: MIT OR Apache-2.0