-
Notifications
You must be signed in to change notification settings - Fork 186
Closed
Description
I have an IndexSet<String> that I want to be able to insert or get index from &str without allocating needlessly if the value is already in the set.
This is actually possible with one small library addition: entry_index. It would return an entry for the value at the index up to and including .len(), thus allowing insertion of the value there. It wouldn't even need to be unsafe: having two keys that compare equal in the map is only very bad for domain correctness, but not for memory correctness if I understand correctly.
It could then be used for inserting if not present with something like the following:
set.get(&key)
.unwrap_or_else(|| set.entry_index(set.len)
.insert(key.to_owned())Metadata
Metadata
Assignees
Labels
No labels