-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
35 lines (28 loc) · 749 Bytes
/
utils.go
File metadata and controls
35 lines (28 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"sort"
"crypto/sha1"
"encoding/binary"
)
func bisectLeftRecord(items []Record, searchKey uint64) int {
return sort.Search(len(items), func(i int) bool { return items[i].id >= searchKey })
}
func bisectLeftNode(items []Node, searchKey uint64) int {
return sort.Search(len(items), func(i int) bool { return items[i].id >= searchKey })
}
func calculateId(key string, m int) (uint64) {
h := sha1.New()
h.Write([]byte(key))
hashedKey := binary.BigEndian.Uint64(h.Sum(nil))
return hashedKey % (1 << uint(m))
}
func assertIdsUnique(records []Record) bool {
idSet := make(map[uint64]bool)
for _, record := range records {
idSet[record.id] = true
}
if len(idSet) != len(records) {
return false
}
return true
}