-
Notifications
You must be signed in to change notification settings - Fork 4
/
hash.go
67 lines (59 loc) · 1.33 KB
/
hash.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
package exectoy
// hashIntOp hashes a column into another column
// TODO(jordan) these are really "projections" where the operator is a hash
// function...
type hashIntOp struct {
input ExecOp
colIdx int
hashColIdx int
}
func (hashIntOp) Init() {}
func (h hashIntOp) Next() dataFlow {
flow := h.input.Next()
if flow.n == 0 {
return flow
}
col := flow.b[h.colIdx].(intColumn)
hashCol := flow.b[h.hashColIdx].(intColumn)
if flow.useSel {
for s := 0; s < flow.n; s++ {
i := flow.sel[s]
hashCol[i] = col[i]
}
} else {
for i := 0; i < flow.n; i++ {
hashCol[i] = col[i]
}
}
return flow
}
// rehashIntOp hashes a column and mixes it with an old hashed column
// Algorithm from Architecture-Conscious Hashing
// http://www.cs.cmu.edu/~./damon2006/pdf/zukowski06archconscioushashing.pdf
type rehashIntOp struct {
input ExecOp
colIdx int
hashColIdx int
}
func (rehashIntOp) Init() {}
func (h rehashIntOp) Next() dataFlow {
flow := h.input.Next()
if flow.n == 0 {
return flow
}
col := flow.b[h.colIdx].(intColumn)
hashCol := flow.b[h.hashColIdx].(intColumn)
if flow.useSel {
for s := 0; s < flow.n; s++ {
i := flow.sel[s]
hash := col[i]
hashCol[i] ^= (hash << 11) ^ (hash >> 7)
}
} else {
for i := 0; i < flow.n; i++ {
hash := col[i]
hashCol[i] ^= (hash << 11) ^ (hash >> 7)
}
}
return flow
}