slotmap icon indicating copy to clipboard operation
slotmap copied to clipboard

Make sure values are unique and return same key for same values

Open myarcana opened this issue 2 years ago • 1 comments

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);

myarcana avatar Dec 01 '22 15:12 myarcana

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.

orlp avatar Dec 01 '22 15:12 orlp