slotmap
slotmap copied to clipboard
Make sure values are unique and return same key for same values
Is this possible? Or is there an easy way to extend slotmap or write a new type of slotmap that supports this?
let mut thing = slotmap::SlotMap::new();
let a = thing.insert("hello");
let b = thing.insert("hello");
assert_eq!(a, b);
Hi, this is commonly known as "string interning", if that helps you. However, slotmap
does not support lookups by arbitrary keys.
You can emulate this by using a HashMap<String, DefaultKey>
together with a SlotMap<DefaultKey, String>
though.