-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.go
80 lines (64 loc) · 1.56 KB
/
util.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package difference_digest
import (
"encoding/binary"
"encoding/hex"
)
type databaseDriver int
const (
// PostgreSQL represents the PostgreSQL database
PostgreSQL databaseDriver = iota
// Snowflake represents the Snowflake database
Snowflake
)
// DatabaseType indicates which type of database to use
var DatabaseType databaseDriver = PostgreSQL
func query(name string) string {
var queries map[string]string
switch DatabaseType {
case PostgreSQL:
queries = postgresQueries
case Snowflake:
queries = snowflakeQueries
}
return queries[name]
}
// Todo: Private
type Bitmap [8]byte
func (bits *Bitmap) IsSet(i int) bool { i -= 1; return bits[i/8]&(1<<uint(7-i%8)) != 0 }
func (bits *Bitmap) Set(i int) { i -= 1; bits[i/8] |= 1 << uint(7-i%8) }
func (bits *Bitmap) Clear(i int) { i -= 1; bits[i/8] &^= 1 << uint(7-i%8) }
func (bits *Bitmap) Sets(xs ...int) {
for _, x := range xs {
bits.Set(x)
}
}
func (bits *Bitmap) XOR(other *Bitmap) {
for i := 1; i <= 64; i++ {
if bits.IsSet(i) != other.IsSet(i) {
bits.Set(i)
} else {
bits.Clear(i)
}
}
}
func (bits *Bitmap) IsZero() bool {
for i := 1; i <= 64; i++ {
if bits.IsSet(i) {
return false
}
}
return true
}
func ToBitmap(n uint64) *Bitmap {
bs := make([]byte, 8)
binary.LittleEndian.PutUint64(bs, n)
bits := Bitmap{}
for i := 0; i < 64; i++ {
if bs[i/8]&(1<<uint(7-i%8)) != 0 {
bits.Set(i + 1)
}
}
return &bits
}
func (bits Bitmap) String() string { return hex.EncodeToString(bits[:]) }
func (bits Bitmap) Uint64() uint64 { return binary.LittleEndian.Uint64(bits[:]) }