EDIT: The only comparison I need is equality comparison.
I’m writing a pattern matching program that involves lots and lots of string comparisons. We are guaranteed there are at most u32 unique values.
I would like some way of representing Strings as u32’s, so comparisons can be fast.
The ‘obvious’ solution seems to be a
Map<String. u32>stored behind some mutex/lock, and every time we create a String, we check vs the map and either get u32 or insert new value and get u32.
This seems like a problem that others must have run into in the past. Is there an idiomatic solution to this?