Crates.io | apma |
lib.rs | apma |
version | 0.1.0 |
created_at | 2025-09-21 16:22:45.244924+00 |
updated_at | 2025-09-21 16:22:45.244924+00 |
description | Adaptive Packed Memory Array (APMA) — a cache-efficient sorted associative container |
homepage | |
repository | https://github.com/krzysztofwos/apma |
max_upload_size | |
id | 1848920 |
size | 72,859 |
A Rust implementation of the Adaptive Packed Memory Array (APMA) data structure, providing an efficient sorted associative container.
The Adaptive Packed Memory Array is a cache-efficient data structure that maintains elements in a sorted order while providing the following benefits:
use apma::Apma;
// Create a new empty APMA
let mut map = Apma::new();
// Insert key-value pairs
map.insert("apple", 5);
map.insert("banana", 3);
map.insert("cherry", 7);
// Lookup values
if let Some(count) = map.get(&"banana") {
println!("Banana count: {}", count);
}
// Remove entries
let removed_value = map.remove(&"apple");
// Iterate through all entries in sorted order
for (key, value) in &map {
println!("{}: {}", key, value);
}
The APMA maintains elements in a packed array with intentional gaps to facilitate efficient insertions and deletions. The key features include:
new()
: Creates a new, empty APMA with default density thresholdswith_thresholds(up_h, up_0, low_h, low_0)
: Creates an APMA with custom density thresholdsfrom_sorted_slice(items)
: Creates an APMA from a pre-sorted slice of key-value pairsinsert(key, value)
: Inserts a key-value pair, returning whether it was a new insertionremove(key)
: Removes a key, returning the associated value if foundget(key)
: Retrieves a reference to the value for a given keycontains_key(key)
: Checks if a key exists in the APMAlen()
: Returns the number of elementsis_empty()
: Checks if the APMA contains no elementscapacity()
: Returns the total capacity (used and unused slots)clear()
: Removes all elementsiter()
: Returns an iterator over all key-value pairs in sorted orderThe data structure is optimized for scenarios requiring sorted key access with frequent modifications, providing better cache performance than traditional tree structures in many cases.
Licensed under either of
at the option of the user.
Unless explicitly stated otherwise, any contribution intentionally submitted for inclusion in the work, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.