-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.go
46 lines (37 loc) · 831 Bytes
/
helper.go
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
36
37
38
39
40
41
42
43
44
45
46
package gobitcask
import (
"encoding/binary"
"fmt"
"strconv"
"strings"
)
func uint32ToBytes(u uint32) []byte {
b := make([]byte, 4)
binary.LittleEndian.PutUint32(b, u)
return b
}
func bytesToUint32(b []byte) uint32 {
return uint32(binary.LittleEndian.Uint32(b))
}
func uint64ToBytes(u uint64) []byte {
b := make([]byte, 8)
binary.LittleEndian.PutUint64(b, u)
return b
}
func bytesToUint64(b []byte) uint64 {
return binary.LittleEndian.Uint64(b)
}
func extractID(filename string) int {
arr := strings.Split(filename, ".")
fileID, _ := strconv.Atoi(arr[0])
return fileID
}
func getSegmentFilename(id int) string {
return fmt.Sprintf("%06d.data", id)
}
func getHintFilename(id int) string {
return fmt.Sprintf("%06d.hint", id)
}
func getMergeFilename(id int) string {
return fmt.Sprintf("%06d.merge", id)
}