MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / mergeKeyValues

Function mergeKeyValues

utils.go:97–135  ·  view source on GitHub ↗
(
	k0, v0 [][]byte,
	k1, v1 [][]byte,
)

Source from the content-addressed store, hash-verified

95}
96
97func mergeKeyValues(
98 k0, v0 [][]byte,
99 k1, v1 [][]byte,
100) (keys, values [][]byte) {
101 l0 := len(k0)
102 l1 := len(k1)
103 // Pre-allocate capacity with estimated maximum size to reduce slice re-growth
104 estimatedSize := l0 + l1
105 keys = make([][]byte, 0, estimatedSize)
106 values = make([][]byte, 0, estimatedSize)
107 cur0 := 0
108 cur1 := 0
109 for cur0 < l0 && cur1 < l1 {
110 if bytes.Compare(k0[cur0], k1[cur1]) <= 0 {
111 keys = append(keys, k0[cur0])
112 values = append(values, v0[cur0])
113 cur0++
114 if bytes.Equal(k0[cur0], k1[cur1]) {
115 // skip k1 item if k0 == k1
116 cur1++
117 }
118 } else {
119 keys = append(keys, k1[cur1])
120 values = append(values, v1[cur1])
121 cur1++
122 }
123 }
124 for cur0 < l0 {
125 keys = append(keys, k0[cur0])
126 values = append(values, v0[cur0])
127 cur0++
128 }
129 for cur1 < l1 {
130 keys = append(keys, k1[cur1])
131 values = append(values, v1[cur1])
132 cur1++
133 }
134 return
135}
136
137// This Type is for sort a pair of (k, v).
138type sortkv struct {

Callers 1

RangeScanEntriesMethod · 0.85

Calls 1

appendFunction · 0.85

Tested by

no test coverage detected