by range. If you think I am asking about that, please reread the email ]
I am trying to define an efficient well-order relation for maps. A well-order relation is described
and in essence requires defining a function
func (i *Item) Less(than *Item) bool
such that if two items i1, i2 are equal
i1.Less(i2) == false AND
i2.Less(i1) == false
and if i1, i2 are non-equal, either
i1.Less(i2) == true OR
i2.Less(i1) == true
but not both
The reason for doing this is to define a Less() operator for (e.g.) a red-black or LLRB tree. Note
that I do not care *what* the well-order relation does.
In this instance the maps are map[string]string, though the content of the maps is largely
irrelevant to the question.
One (inefficient) algorithm would be as follows:
1. If len(i1)<len(i2), i1<i2, else if len(i2)<len(i1), i2<i1
2. produce a union of they keys of each map
3. sort the union of the keys
4. iterate through the sorted union of the keys in order
if the key only appears in i1, i2<i1
if the key only appears in i2, i1>i2
if i1[key]<i2[key], i1<i2
if i2[key]<i1[key], i2<i1
I suspect I could skip step 3, provided that golang guarantees that the iteration order of any hash is constant during any run.
Another approach would be simply to hash the map and its contents.
Is there a faster/more efficient way to do this?
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firstname.lastname@example.org.
For more options, visit https://groups.google.com/d/optout.