-
Notifications
You must be signed in to change notification settings - Fork 12
/
row.go
37 lines (31 loc) · 639 Bytes
/
row.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
package datatable
import (
"bytes"
"encoding/gob"
"github.com/cespare/xxhash"
)
// Row contains a row relative to columns
type Row map[string]interface{}
// Set cell
func (r Row) Set(k string, v interface{}) Row {
r[k] = v
return r
}
// Get cell
func (r Row) Get(k string) interface{} {
// Check colName exists
if v, ok := r[k]; ok {
return v
}
return nil
}
// Hash computes the hash code from this datarow
// can be used to filter the table (distinct rows)
func (r Row) Hash() uint64 {
buff := new(bytes.Buffer)
enc := gob.NewEncoder(buff)
for _, v := range r {
enc.Encode(v)
}
return xxhash.Sum64(buff.Bytes())
}