Commit 2f90a5da authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent c9e9d6c7
......@@ -373,3 +373,34 @@ func TestIntSets(t *testing.T) {
t.Fatalf("error:\ngot: %v\nwant: %v", got, want)
}
}
// kvdiff returns differens in between kv1 and kv2.
var DEL = "ø"
type kvdelta1 struct {
k Key
v string // DEL means delete
}
func kvdiff(kv1, kv2 map[Key]string) []kvdelta1 {
delta := []kvdelta1{}
keys := SetI64{}
for k := range kv1 { keys.Add(k) }
for k := range kv2 { keys.Add(k) }
keyv := []Key{}
for k := range keys { keyv = append(keyv, k) }
sort.Slice(keyv, func(i,j int) bool {
return keyv[i] < keyv[j]
})
for _, k := range keyv {
v1, ok := kv1[k]
if !ok { v1 = DEL }
v2, ok := kv2[k]
if !ok { v2 = DEL }
if v1 != v2 {
delta = append(delta, kvdelta1{k,v2})
}
}
return delta
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment