Skip to content

A cache data structure which generates sequentially-assigned ids for unique values

License

Notifications You must be signed in to change notification settings

exists-forall/id_cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

id_cache

Download: crates.io/crates/id_cache

Docs: docs.rs/id_cache


This is a small crate built on id_collections which provides a simple "cache" data structure for generating sequentially-assigned ids for unique values of some hashable type.

Example

use id_collections::id_type;
use id_cache::IdCache;

#[id_type]
struct WordId(u32);

let mut word_cache: IdCache<WordId, &str> = IdCache::new();

let foo_id = word_cache.make_id("foo");
let bar_id = word_cache.make_id("bar");

assert_eq!(word_cache[foo_id], "foo");
assert_eq!(word_cache[bar_id], "bar");

// ids for repeated values are reused:
assert_eq!(word_cache.make_id("foo"), foo_id);

Optional Features

This crate has optional Serde support, which can be enabled with the serde Cargo feature.

About

A cache data structure which generates sequentially-assigned ids for unique values

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages