本文整理汇总了Golang中github.com/dchest/siphash.Hash函数的典型用法代码示例。如果您正苦于以下问题:Golang Hash函数的具体用法?Golang Hash怎么用?Golang Hash使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Hash函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: makeId
func makeId(dv driver.Value) uint64 {
switch vt := dv.(type) {
case int:
return uint64(vt)
case int64:
return uint64(vt)
case []byte:
return siphash.Hash(0, 1, vt)
// iv, err := strconv.ParseUint(string(vt), 10, 64)
// if err != nil {
// u.Warnf("could not create id: %v for %v", err, dv)
// }
// return iv
case string:
return siphash.Hash(0, 1, []byte(vt))
// iv, err := strconv.ParseUint(vt, 10, 64)
// if err != nil {
// u.Warnf("could not create id: %v for %v", err, dv)
// }
// return iv
case *Key:
//u.Infof("got %#v", vt)
return vt.Id
case datasource.KeyCol:
//u.Infof("got %#v", vt)
return makeId(vt.Val)
default:
//u.LogTracef(u.WARN, "wat")
u.Warnf("not implemented conversion: %T", dv)
}
return 0
}
开发者ID:schmichael,项目名称:qlbridge,代码行数:32,代码来源:btree.go
示例2: New
// New Replica Factor 1 with random
func New(randomized bool) *RF1R {
res := RF1R{}
if randomized {
res.hasher1 = func(b []byte) uint64 { return siphash.Hash(0, 0, b) }
res.hasher2 = func(b []byte) uint64 { return siphash.Hash(2, 3, b) }
} else {
res.hasher1 = func(b []byte) uint64 { return siphash.Hash(0, 0, b) }
res.hasher2 = func(b []byte) uint64 { return siphash.Hash(0, 0, b) }
}
return &res
}
开发者ID:Civil,项目名称:graphite-rf-test,代码行数:14,代码来源:rf1r.go
示例3: BenchmarkSipHashFast
func BenchmarkSipHashFast(b *testing.B) {
var key0, key1 uint64 = 0, 1
b.StartTimer()
for i := 0; i < b.N; i++ {
siphash.Hash(key0, key1, []byte("Hello World"))
}
}
开发者ID:araddon,项目名称:goperf,代码行数:7,代码来源:hashing_test.go
示例4: Add
func (t *T) Add(key string, val interface{}) {
newitem := slruItem{0, key, val, siphash.Hash(0, 0, stringToSlice(key))}
oitem, evicted := t.lru.add(newitem)
if !evicted {
return
}
// estimate count of what will be evicted from slru
victim := t.slru.victim()
if victim == nil {
t.slru.add(oitem)
return
}
if !t.bouncer.allow(oitem.keyh) {
return
}
vcount := t.c.estimate(victim.keyh)
ocount := t.c.estimate(oitem.keyh)
if ocount < vcount {
return
}
t.slru.add(oitem)
}
开发者ID:maximecaron,项目名称:go-tinylfu,代码行数:29,代码来源:tinylfu.go
示例5: New
// New Replica Factor 1 with random
func New() *RF2 {
res := RF2{}
res.hasher = func(b []byte) uint64 { return siphash.Hash(0, 0, b) }
return &res
}
开发者ID:Civil,项目名称:graphite-rf-test,代码行数:8,代码来源:rf2.go
示例6: main
func main() {
verbose := flag.Bool("v", false, "verbose")
flag.Parse()
scanner := bufio.NewScanner(os.Stdin)
w := bufio.NewWriter(os.Stdout)
defer w.Flush()
for scanner.Scan() {
fname := scanner.Text()
b, err := ioutil.ReadFile(fname)
if err != nil {
log.Println(err)
continue
}
sip := siphash.Hash(0, 0, b)
data, err := lz4.Encode(nil, b)
if err != nil {
log.Println("error packing: ", err)
continue
}
const headerSize = 4 + 8 + 2 + 4 // + len(fname)
h := struct {
PacketSize uint32
SipHash uint64
Fname []byte `binpack:"lenprefix=uint16"`
UncompressedSize uint32
}{
PacketSize: uint32(headerSize + len(fname) + len(data)),
SipHash: sip,
Fname: []byte(fname),
UncompressedSize: uint32(len(b)),
}
if *verbose {
log.Printf("%s: %d -> %d\n", fname, len(b), len(data))
}
err = binpack.Write(w, binary.LittleEndian, h)
if err != nil {
log.Printf("error writing header %+v\n", err)
break
}
_, err = w.Write(data)
if err != nil {
log.Printf("error writing %+v\n", err)
break
}
}
}
开发者ID:KanwarGill,项目名称:trifles,代码行数:60,代码来源:lz4pack.go
示例7: SendCmpctBlk
func (c *OneConnection) SendCmpctBlk(hash *btc.Uint256) {
crec := GetchBlockForBIP152(hash)
if crec == nil {
fmt.Println(c.ConnID, "cmpctblock not sent for", hash.String())
return
}
k0 := binary.LittleEndian.Uint64(crec.BIP152[8:16])
k1 := binary.LittleEndian.Uint64(crec.BIP152[16:24])
msg := new(bytes.Buffer)
msg.Write(crec.Data[:80])
msg.Write(crec.BIP152[:8])
btc.WriteVlen(msg, uint64(len(crec.Block.Txs)-1)) // all except coinbase
for i := 1; i < len(crec.Block.Txs); i++ {
var lsb [8]byte
var hasz *btc.Uint256
if c.Node.SendCmpctVer == 2 {
hasz = crec.Block.Txs[i].WTxID()
} else {
hasz = crec.Block.Txs[i].Hash
}
binary.LittleEndian.PutUint64(lsb[:], siphash.Hash(k0, k1, hasz.Hash[:]))
msg.Write(lsb[:6])
}
msg.Write([]byte{1}) // one preffiled tx
msg.Write([]byte{0}) // coinbase - index 0
if c.Node.SendCmpctVer == 2 {
msg.Write(crec.Block.Txs[0].Raw) // coinbase - index 0
} else {
crec.Block.Txs[0].WriteSerialized(msg) // coinbase - index 0
}
c.SendRawMsg("cmpctblock", msg.Bytes())
}
开发者ID:piotrnar,项目名称:gocoin,代码行数:34,代码来源:cblk.go
示例8: Hash
// Hash returns a simhash value for the document returned by the scanner
func Hash(scanner FeatureScanner) uint64 {
var signs [64]int64
for scanner.Scan() {
b := scanner.Bytes()
h := siphash.Hash(0, 0, b)
for i := 0; i < 64; i++ {
negate := int(h) & 1
// if negate is 1, we will negate '-1', below
r := (-1 ^ -negate) + negate
signs[i] += int64(r)
h >>= 1
}
}
var shash uint64
// TODO: can probably be done with SSE?
for i := 63; i >= 0; i-- {
shash <<= 1
shash |= uint64(signs[i]>>63) & 1
}
return shash
}
开发者ID:xukai504087493,项目名称:go-simstore,代码行数:27,代码来源:simhash.go
示例9: Get
func (t *T) Get(key string) (interface{}, bool) {
t.w++
if t.w == t.samples {
t.c.reset()
t.bouncer.reset()
t.w = 0
}
val, ok := t.data[key]
if !ok {
keyh := siphash.Hash(0, 0, stringToSlice(key))
t.c.add(keyh)
return nil, false
}
item := val.Value.(*slruItem)
t.c.add(item.keyh)
v := item.value
if item.listid == 0 {
t.lru.get(val)
} else {
t.slru.get(val)
}
return v, true
}
开发者ID:maximecaron,项目名称:go-tinylfu,代码行数:29,代码来源:tinylfu.go
示例10: main
func main() {
f := flag.String("f", "/dev/stdin", "input file")
n := flag.Int("n", 100e6, "cardinality estimate of set")
fprate := flag.Float64("fp", 0.00000001, "false positive rate")
flag.Parse()
file, err := os.Open(*f)
if err != nil {
log.Fatal(err)
}
var lines int
b := bloomf.New(*n, *fprate, func(b []byte) uint64 { return siphash.Hash(0, 0, b) })
scanner := bufio.NewScanner(file)
for scanner.Scan() {
lines++
if !b.Lookup(scanner.Bytes()) {
os.Stdout.Write(scanner.Bytes())
os.Stdout.Write([]byte("\n"))
}
b.Insert(scanner.Bytes())
if lines%(1<<20) == 0 {
log.Println(lines)
}
}
}
开发者ID:KanwarGill,项目名称:trifles,代码行数:29,代码来源:main.go
示例11: Set
func (d *Dict) Set(key []byte, value interface{}) {
p := siphash.Hash(d.k0, d.k1, key) % dictSize
node := d.data[p]
if node == nil {
d.data[p] = &dictNode{
k: key,
v: value,
next: nil,
}
d.size += 1
return
}
for {
if bytes.Equal(node.k, key) {
node.v = value
return
}
if node.next != nil {
node = node.next
continue
}
node.next = &dictNode{
k: key,
v: value,
next: nil,
}
d.size += 1
return
}
}
开发者ID:runique,项目名称:golly,代码行数:30,代码来源:dict.go
示例12: Delete
func (d *Dict) Delete(key []byte) {
p := siphash.Hash(d.k0, d.k1, key) % dictSize
node := d.data[p]
if node == nil {
return
}
if bytes.Equal(node.k, key) {
d.data[p] = nil
d.size -= 1
return
}
next := node.next
for {
if next == nil {
return
}
if bytes.Equal(next.k, key) {
node.next = next.next
d.size -= 1
return
}
next = node.next
}
panic("unreachable code")
}
开发者ID:runique,项目名称:golly,代码行数:25,代码来源:dict.go
示例13: main
func main() {
scan := bufio.NewScanner(os.Stdin)
for scan.Scan() {
u := siphash.Hash(0, 0, scan.Bytes())
fmt.Printf("%016x\n", u)
}
}
开发者ID:dgryski,项目名称:trifles,代码行数:9,代码来源:main.go
示例14: hashOne
func hashOne(k0, k1 uint64, r io.Reader, name string) {
buf, err := ioutil.ReadAll(r)
if err != nil {
log.Println(name, err)
return
}
h := siphash.Hash(k0, k1, buf)
fmt.Printf("%016x %s\n", h, name)
}
开发者ID:dgryski,项目名称:trifles,代码行数:9,代码来源:main.go
示例15: sipuintptr
func sipuintptr(s []uintptr) uint64 {
b := make([]byte, len(s)*8)
for i, v := range s {
binary.LittleEndian.PutUint64(b[i*8:], uint64(v))
}
return siphash.Hash(0, 0, b)
}
开发者ID:ab5tract,项目名称:Sereal,代码行数:10,代码来源:main.go
示例16: Benchmark_Siphash
func Benchmark_Siphash(b *testing.B) {
size := 1024
k1, k2 := uint64(rand.Int63()), uint64(rand.Int63())
msg := randArray(size)
b.SetBytes(int64(size))
b.ResetTimer()
for i := 0; i < b.N; i++ {
siphash.Hash(k1, k2, msg)
}
}
开发者ID:noscripter,项目名称:deblocus,代码行数:11,代码来源:d5_test.go
示例17: TestSiphash
func TestSiphash(t *testing.T) {
k1, k2 := uint64(rand.Int63()), uint64(rand.Int63())
msg := randArray(1 << 9) // 512B
var loop int = 2e6
t1 := time.Now()
for i := 0; i < loop; i++ {
siphash.Hash(k1, k2, msg)
}
tu := float64(time.Since(t1).Nanoseconds()) / 1e9
t.Logf("tu=%.2fms speed=%.2fm", tu*1e3, float64(loop*len(msg))/float64(1<<20)/tu)
}
开发者ID:angle1895,项目名称:deblocus,代码行数:11,代码来源:d5_test.go
示例18: timeErrorUnit
func timeErrorUnit(sp []byte, errors int) bool {
_, _, hk := extractKeys(sp)
// generate
head := makeDbcHello(1, sp)
// make error
tc := uint64(time.Now().Unix()/TIME_STEP + int64(errors))
errSum := siphash.Hash(hk, tc, head[:DPH_LEN1])
binary.BigEndian.PutUint64(head[DPH_LEN1:], errSum)
// verify
tcArr := calculateTimeCounter(true)
ok, _, _ := verifyDbcHello(head, sp, tcArr)
return ok
}
开发者ID:noscripter,项目名称:deblocus,代码行数:13,代码来源:d5_test.go
示例19: makeDbcHello
func makeDbcHello(data byte, secret []byte) []byte {
randLen := rand.Int() % DP_LEN1 // 8bit
buf := randArray(randLen + DP_P2I)
pos, sKey, hKey := extractKeys(secret)
// actually f is uint16
f := (randLen << 8) | int(data)
f = (f + sKey) % DP_MOD
binary.BigEndian.PutUint16(buf[pos:pos+2], uint16(f))
sum := siphash.Hash(hKey, calculateTimeCounter(false)[0], buf[:DP_LEN1])
binary.BigEndian.PutUint64(buf[DP_LEN1:DP_P2I], sum)
return buf
}
开发者ID:ghmajx,项目名称:deblocus,代码行数:14,代码来源:d5.go
示例20: Lookup
// Lookup queries the cuckoo filter for an item
func (cf *CF) Lookup(x []byte) bool {
h := siphash.Hash(0, 0, x)
i1 := uint32(h) % uint32(len(cf.t))
f := byte(h >> 32)
if cf.hasFP(i1, f) {
return true
}
i2 := (i1 ^ hashfp(f)) % uint32(len(cf.t))
return cf.hasFP(i2, f)
}
开发者ID:mirrr,项目名称:go-cuckoof,代码行数:16,代码来源:cuckoof.go
注:本文中的github.com/dchest/siphash.Hash函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论