diff options
| author | Russ Cox <rsc@golang.org> | 2008-12-19 03:05:37 -0800 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2008-12-19 03:05:37 -0800 |
| commit | 08ca30bbfad04d3ca1bf7ae75c291b91ecb00aef (patch) | |
| tree | 183e8cd345f5f895d2cbc36dd8f8be93640303c3 /test/hashmap.go | |
| parent | d47d888ba663014e6aa8ca043e694f4b2a5898b8 (diff) | |
| download | go-08ca30bbfad04d3ca1bf7ae75c291b91ecb00aef.tar.xz | |
change *map to map; *chan to chan; new(T) to new(*T)
fix bugs left over from *[] to [] conversion.
TBR=r
OCL=21576
CL=21581
Diffstat (limited to 'test/hashmap.go')
| -rwxr-xr-x | test/hashmap.go | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/test/hashmap.go b/test/hashmap.go index 86a3422726..d458b8c973 100755 --- a/test/hashmap.go +++ b/test/hashmap.go @@ -64,7 +64,7 @@ func (m *HashMap) Clear() { func (m *HashMap) Initialize (initial_log2_capacity uint32) { m.log2_capacity_ = initial_log2_capacity; - m.map_ = new([1024] Entry); + m.map_ = new(*[1024] Entry); m.Clear(); } @@ -74,7 +74,7 @@ func (m *HashMap) Probe (key *KeyType) *Entry { var i uint32 = key.Hash() % m.capacity(); ASSERT(0 <= i && i < m.capacity()); - + ASSERT(m.occupancy_ < m.capacity()); // guarantees loop termination for m.map_[i].key != nil && !m.map_[i].key.Match(key) { i++; @@ -82,7 +82,7 @@ func (m *HashMap) Probe (key *KeyType) *Entry { i = 0; } } - + return &m.map_[i]; } @@ -102,13 +102,13 @@ func (m *HashMap) Lookup (key *KeyType, insert bool) *Entry { p.key = key; p.value = nil; m.occupancy_++; - + // Grow the map if we reached >= 80% occupancy. if m.occupancy_ + m.occupancy_/4 >= m.capacity() { m.Resize(); p = m.Probe(key); } - + return p; } @@ -120,10 +120,10 @@ func (m *HashMap) Lookup (key *KeyType, insert bool) *Entry { func (m *HashMap) Resize() { var hmap *[1024] Entry = m.map_; var n uint32 = m.occupancy_; - + // Allocate a new map of twice the current size. m.Initialize(m.log2_capacity_ << 1); - + // Rehash all current entries. var i uint32 = 0; for n > 0 { @@ -157,7 +157,7 @@ func (n *Number) Match(other *KeyType) bool { func MakeNumber (x uint32) *Number { - var n *Number = new(Number); + var n *Number = new(*Number); n.x = x; return n; } @@ -167,18 +167,18 @@ func main() { //f unc (n int) int { return n + 1; }(1); //print "HashMap - gri 2/8/2008\n"; - - var hmap *HashMap = new(HashMap); + + var hmap *HashMap = new(*HashMap); hmap.Initialize(0); - + var x1 *Number = MakeNumber(1001); var x2 *Number = MakeNumber(2002); var x3 *Number = MakeNumber(3003); - + // this doesn't work I think... //hmap.Lookup(x1, true); //hmap.Lookup(x2, true); //hmap.Lookup(x3, true); - + //print "done\n"; } |
