I can't find a good way to do this. I want to have a map from a list of sorted key-value pairs.
type Tag struct {
key string
value string
}
type SortedTag []Tag // sorted list of tags.
map[SortedTags]T // cannot do.
I can solve this problem by joining all the key-value pairs with a delimiter, but I feel like this is inefficient and error prone in many ways. Converting back to the key-value pair is cumbersome because we need to split the input. moreover, if the key value pair can be anything, that means we have to escape it.
If it was python, I would've stored Tag
as N-tuple of sorted 2-tupless.
If it was java, I would've created a composite object with Map<String,String>
with equals()
checking against the other hash map, hashCode()
returning the xor
of all the hashes of the map (xor
since it is commutative thus we can iterate the map in any order to compute this value).
In go, I can't think of any other good way.