orderedmap
orderedmap copied to clipboard
map is not sorted
var rs map[string][]byte
// 排序
m := orderedmap.NewOrderedMap()
for k, _ := range rs {
fmt.Printf(" |-set-> %v\n", el.Key)
m.Set(k, rs[k])
}
// You can also use Back and Prev to iterate in reverse:
for el := m.Back(); el != nil; el = el.Prev() {
fmt.Printf(" |-get-> %v\n", el.Key)
}
----> 检索记录,前缀: auth_file_rec-001203-0100000084-
out--find more--> [auth_file_rec-001203-0100000084-%!s(int=23)]:
out--find more--> [auth_file_rec-001203-0100000084-%!s(int=24)]:
out--find more--> [auth_file_rec-001203-0100000084-%!s(int=25)]:
out--find more--> [auth_file_rec-001203-0100000084-%!s(int=26)]:
|---> auth_file_rec-001203-0100000084-%!s(int=26)
|---> auth_file_rec-001203-0100000084-%!s(int=25)
|---> auth_file_rec-001203-0100000084-%!s(int=24)
|---> auth_file_rec-001203-0100000084-%!s(int=23)
----> 检索记录,前缀: auth_file_rec-001203-0100000084-
out--find more--> [auth_file_rec-001203-0100000084-%!s(int=23)]:
out--find more--> [auth_file_rec-001203-0100000084-%!s(int=24)]:
out--find more--> [auth_file_rec-001203-0100000084-%!s(int=25)]:
out--find more--> [auth_file_rec-001203-0100000084-%!s(int=26)]:
|---> auth_file_rec-001203-0100000084-%!s(int=24)
|---> auth_file_rec-001203-0100000084-%!s(int=23)
|---> auth_file_rec-001203-0100000084-%!s(int=26)
|---> auth_file_rec-001203-0100000084-%!s(int=25)
I cannot understand your output because it doesn't match the code you provided.
This package does not provide a sorted map (where items are placed in sorted order), it is an ordered map (where insert order is maintained).