func BenchmarkAddGetHighLoad(b *testing.B) { var h hophash.HashMap var coder hophash.HashCoder coder = new(fnvHash) h = hophash.NewHophash(coder, 16, 28) for i := uint64(0); i < uint64(math.Pow(2, 20)); i++ { testAddGet(h, i, b) } }
func BenchmarkAddGet(b *testing.B) { var h hophash.HashMap var coder hophash.HashCoder coder = new(fnvHash) h = hophash.NewHophash(coder, 64, 28) for i := 0; i < b.N; i++ { testAddGet(h, uint64(i), b) } }
func main() { var h hophash.HashMap var coder hophash.HashCoder coder = new(fnvHash) h = hophash.NewHophash(coder, 32, uint64(math.Pow(2, 16))) h.Add("key1", "value1") val, ok := h.Get("key1") if ok { fmt.Println(val) } else { fmt.Println("no value present") } }
func testAddFirstGetLater(b *testing.B, power int) { var h hophash.HashMap var coder hophash.HashCoder coder = new(fnvHash) h = hophash.NewHophash(coder, 32, power) n := uint64(math.Pow(2, float64(power))) firstPart := uint64(n / 10) // do 10% inserts first for i := uint64(0); i < firstPart; i++ { str := strconv.FormatUint(i, 10) h.Add(str, str) } // now do contains with some misses and so hits // if "i" is even we should try successfull hit // if not we will try a miss for i := (n - firstPart); i < n; i++ { if i%2 == 0 { str := strconv.FormatUint((i / 100), 10) value, ok := h.Get(str) if !ok { b.Fatal("value not found") return } if value != str { b.Fatal("value not same as what was added") return } } else { str := strconv.FormatUint(i, 10) _, ok := h.Get(str) if ok { b.Fatal("This key should not have been found") } } } }