Expand description
§ByteBox Crate
The ByteBox crate provides a custom hash map implementation optimized for byte slices.
It allows you to map keys of type Vec<u8> to values of type Vec<u8>, offering an efficient
way to work with raw byte data without unnecessary cloning or allocations.
§Features
- Custom Hash Function (
hpulse): Utilizes a bespoke hash function designed for efficient hashing of byte slices. - Collision Resolution via Linked Lists: Handles hash collisions using linked lists (chaining), ensuring that all entries are accessible even when collisions occur.
- Dynamic Resizing: Automatically resizes the underlying storage when the load factor exceeds a predefined threshold, maintaining optimal performance.
- Customizable Initial Allocation: Provides constructors to create a
ByteBoxwith a default allocation or a specified allocation.
§Important Considerations
- Ownership: The
ByteBoxnow owns the keys and values (Vec<u8>), eliminating lifetime management issues. This means that the data inserted into theByteBoxis fully owned by the structure and will be cleaned up when it is dropped.
§Example
use bytesbox::ByteBox;
fn main() {
let key = b"hello";
let value = b"world";
let mut byte_box = ByteBox::new();
byte_box.insert(key, value);
if let Some(val) = byte_box.get(key) {
println!("Key: {:?}, Value: {:?}", key, val);
}
}§Safety Notes
- The
removemethod usesunsafecode to manipulate pointers for efficient removal of entries. Care has been taken to ensure this is safe, but users should be aware of the risks associated withunsafeblocks.
§License
This crate is provided under the Apache-2.0 License.
Structs§
- A hash map implementation optimized for byte slices as keys and values.
- An iterator over the key-value pairs in a
ByteBox.