-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (46 loc) · 861 Bytes
/
main.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
package main
import (
"crypto/rand"
"crypto/sha512"
"log"
"math"
"number/hash/bloomfilter"
"time"
)
func main(){
n:=15;
lambda:=6;
hash:=sha512.New();
blf,_:=bloomfilter.Newbloomfilter(n,lambda,hash);
buf:=make([]byte,8);
var cache [][]byte
for i:=0;i<n;i++{
rand.Read(buf)
cache=append(cache,buf);
}
for i:=0;i<len(cache);i++{
//log.Println(cache[i])
blf.AddElement(cache[i],hash)
}
//log.Println("Witness",blf.Witness)
ch:=make([]byte,8)
/*
for i:=0;i<len(cache);i++{
//log.Println(cache[i])
if blf.VerifyElement(cache[i],hash){
log.Println(i,true)
}
}*/
var steps =int(0)
start:=time.Now()
var t time.Duration
for i:=0;;i++{
rand.Read(ch);
if blf.VerifyElement(ch,hash){
t=time.Now().Sub(start)
steps=i;
break
}
}
log.Printf("average steps2^(%f),time=%v\n",math.Log2(float64(steps)),t.Seconds())
}