Skip to content

Commit

Permalink
trace and random run support
Browse files Browse the repository at this point in the history
  • Loading branch information
tildeleb committed Sep 28, 2017
1 parent 7c2896f commit 3dda215
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
4 changes: 4 additions & 0 deletions hashf/hashf.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ func Hashf(k []byte, seed uint64) (h uint64) {
case "gomap32":
h = uint64(gomap.Hash32(k, uint32(seed)))
case "aeshash64":
//fmt.Printf("k=%v\n", k)
h = aeshash.Hash(k, seed)
case "aeshash32I":
//fmt.Printf("k=%v\n", k)
h = aeshash.Hash64(uint64(k[0])<<24|uint64(k[1])<<16|uint64(k[2])<<8|uint64(k[3])<<0, seed)
case "aeshash64I":
h = aeshash.Hash64(uint64(k[0])<<56|uint64(k[1])<<48|uint64(k[2])<<40|uint64(k[3])<<32|uint64(k[4])<<24|uint64(k[5])<<16|uint64(k[6])<<8|uint64(k[7])<<0, seed)
case "adler32":
Expand Down
25 changes: 13 additions & 12 deletions hashtable/hashtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ type Bucket struct {
}

type Stats struct {
Inserts int
Cols int
Probes int
Heads int
Dups int
Nbuckets int
Inserts int // number of elements inserted
Cols int // number of collisions
Probes int // number of probes
Heads int // number of chains > 1
Dups int // number of dup keys
Nbuckets int // number of new buckets added
Entries int
LongestChain int
LongestChain int // longest chain of entries
Q float64
Dur time.Duration
//
Expand Down Expand Up @@ -107,7 +107,7 @@ func NewHashTable(size int, seed int64, extra int, pd, oa, prime bool) *HashTabl
ht.SizeMask = ht.Size - 1
ht.Buckets = make([][]Bucket, ht.Size, ht.Size)

ht.Nbuckets = int(ht.Size)
//ht.Nbuckets = int(ht.Size)
return ht
}

Expand Down Expand Up @@ -210,6 +210,7 @@ func (ht *HashTable) Insert(ka []byte) {
// add element
ht.Buckets[idx] = append(ht.Buckets[idx], Bucket{Key: k})
if len(ht.Buckets[idx]) > ht.LongestChain {
//fmt.Printf("len(ht.Buckets[idx])=%d, ht.LongestChain=%d\n", len(ht.Buckets[idx]), ht.LongestChain)
ht.LongestChain = len(ht.Buckets[idx])
}
if Trace {
Expand Down Expand Up @@ -283,9 +284,9 @@ func (s *HashTable) Print() {
panic("runTestsWithFileAndHashes")
}
*/
fmt.Printf("size=%h, inserts=%04.2h, buckets=%04.2h, newBuckets=%04.2h, LongestChain=%d, dups=%d, q=%0.2f, time=%0.2f%s\n",
hrff.Int64{int64(s.Size), ""}, hrff.Float64{float64(s.Inserts), ""}, hrff.Float64{float64(s.Nbuckets), ""},
hrff.Float64{float64(s.LongestChain), ""}, hrff.Float64{float64(s.Nbuckets - int(s.Size)), ""},
s.Dups, q, t, units)
//fmt.Printf("%#v\n", s)
fmt.Printf("size=%h, inserts=%h, heads=%h, newBuckets=%h, LongestChain=%h, dups=%d, q=%0.2f, time=%0.2f%s\n",
hrff.Int64{int64(s.Size), ""}, hrff.Int64{int64(s.Inserts), ""}, hrff.Int64{int64(s.Heads), ""},
hrff.Int64{int64(s.Nbuckets), ""}, hrff.Int64{int64(s.LongestChain), ""}, s.Dups, q, t, units)
}
}
3 changes: 3 additions & 0 deletions ht.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,9 @@ func runTestsWithFileAndHashes(file string, lines int, hf []string) {
}
fmt.Printf("\t%20q: ", Hf2)
ht := test.ptf(file, lines, Hf2)
if *rr || *s != 0 {
fmt.Printf("seed=%#016x\n", seed)
}
ht.Print()
}
}
Expand Down

0 comments on commit 3dda215

Please sign in to comment.