@ -2,6 +2,7 @@ package graphvent
import (
import (
"crypto/ecdh"
"crypto/ecdh"
"sort"
"time"
"time"
"encoding/binary"
"encoding/binary"
"errors"
"errors"
@ -975,6 +976,11 @@ func NewContext(db * badger.DB, log Logger) (*Context, error) {
map_size := 0
map_size := 0
map_iter := value . MapRange ( )
map_iter := value . MapRange ( )
type TreeMapValue struct {
Key SerializedType
Data [ ] byte
}
value_stacks := [ ] TreeMapValue { }
for map_iter . Next ( ) {
for map_iter . Next ( ) {
map_size += 1
map_size += 1
key_reflect := map_iter . Key ( )
key_reflect := map_iter . Key ( )
@ -989,8 +995,19 @@ func NewContext(db * badger.DB, log Logger) (*Context, error) {
return SerializedValue { } , err
return SerializedValue { } , err
}
}
data = append ( data , key_value . Data ... )
value_stacks = append ( value_stacks , TreeMapValue {
data = append ( data , elem_value . Data ... )
SerializedType ( key_reflect . Uint ( ) ) ,
append ( key_value . Data , elem_value . Data ... ) ,
} )
}
// Sort the value_stacks, then add them to `data`
sort . Slice ( value_stacks , func ( i , j int ) bool {
return value_stacks [ i ] . Key > value_stacks [ j ] . Key
} )
for _ , stack := range ( value_stacks ) {
data = append ( data , stack . Data ... )
}
}
binary . BigEndian . PutUint64 ( data [ 0 : 8 ] , uint64 ( map_size ) )
binary . BigEndian . PutUint64 ( data [ 0 : 8 ] , uint64 ( map_size ) )