Crates.io | hotel |
lib.rs | hotel |
version | 1.0.5 |
source | src |
created_at | 2022-01-04 22:06:04.013895 |
updated_at | 2023-11-06 09:42:41.268679 |
description | Collection Data-structure to associate values with keys |
homepage | |
repository | |
max_upload_size | |
id | 508079 |
size | 10,596 |
Simple collection datastructure to associate data with unique keys.
The key is of type usize
, and can therefore cheaply be passed around in favour of the actual data.
The advantage is that keys
can be cloned unbeatable cheaply and no hashing of keys has to ever take place. This also means no collisions can ever happen.
put
, remove
, get
, take
are all O(1) operations.
The Hotel
is backed by a Vec
and is very memory efficient. Thanks to this it's very much efficient to use on modern CPUs by virtue of inheriting the Vec
s cache-friendliness.
Here are examples
HashMap
replacement.Hotel
is the perfect place to store ownership of the Nodes and manage edges as keys.here's a simple Graph. A -> B -> C
let mut nodes: Hotel<Node>,
let mut edges: Vec<(usize, usize)>
let key1 = nodes.put(Node::new(a));
let key2 = nodes.put(Node::new(b));
let key3 = nodes.put(Node::new(c));
edges.push( (key1, key2) );
edges.push( (key2, key3) );
Additionally, this crate contains the HotelMap datastructure.
It's a shorthand for mapping keys to simple usize values, and being able to index with both.
This can have the advantage of being able to use copyable and small usize
, instead of carrying around complex and large keys all the time.