aboutsummaryrefslogtreecommitdiff
path: root/test/bigmap.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2012-05-24 22:41:07 -0400
committerRuss Cox <rsc@golang.org>2012-05-24 22:41:07 -0400
commitbf18d57d4a186302ed7a3b07d60cd6facda08a71 (patch)
tree1f60425e5b47be3cd0d135615667fb2cf0ec6d7e /test/bigmap.go
parentca6b4d535f56dbfd0f0334bc7747bde20914d7b2 (diff)
downloadgo-bf18d57d4a186302ed7a3b07d60cd6facda08a71.tar.gz
go-bf18d57d4a186302ed7a3b07d60cd6facda08a71.zip
runtime: handle and test large map values
This is from CL 5451105 but was dropped from that CL. See also CL 6137051. The only change compared to 5451105 is to check for h != nil in reflect·mapiterinit; allowing use of nil maps must have happened after that original CL. Fixes #3573. R=golang-dev, dave, r CC=golang-dev https://golang.org/cl/6215078
Diffstat (limited to 'test/bigmap.go')
-rw-r--r--test/bigmap.go105
1 files changed, 104 insertions, 1 deletions
diff --git a/test/bigmap.go b/test/bigmap.go
index 37e0498467..c5e4f91e11 100644
--- a/test/bigmap.go
+++ b/test/bigmap.go
@@ -4,7 +4,9 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// Test behavior of maps with large elements.
+// Internally a map holds elements in up to 255 bytes of key+value.
+// When key or value or both are too large, it uses pointers to key+value
+// instead. Test all the combinations.
package main
@@ -33,4 +35,105 @@ func main() {
cmp(m[1], seq(11, 13))
cmp(m[2], seq(2, 9))
cmp(m[3], seq(3, 17))
+
+
+ {
+ type T [1]byte
+ type V [1]byte
+ m := make(map[T]V)
+ m[T{}] = V{1}
+ m[T{1}] = V{2}
+ if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 {
+ println(x, y)
+ panic("bad map")
+ }
+ }
+ {
+ type T [100]byte
+ type V [1]byte
+ m := make(map[T]V)
+ m[T{}] = V{1}
+ m[T{1}] = V{2}
+ if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 {
+ println(x, y)
+ panic("bad map")
+ }
+ }
+ {
+ type T [1]byte
+ type V [100]byte
+ m := make(map[T]V)
+ m[T{}] = V{1}
+ m[T{1}] = V{2}
+ if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 {
+ println(x, y)
+ panic("bad map")
+ }
+ }
+ {
+ type T [1000]byte
+ type V [1]byte
+ m := make(map[T]V)
+ m[T{}] = V{1}
+ m[T{1}] = V{2}
+ if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 {
+ println(x, y)
+ panic("bad map")
+ }
+ }
+ {
+ type T [1]byte
+ type V [1000]byte
+ m := make(map[T]V)
+ m[T{}] = V{1}
+ m[T{1}] = V{2}
+ if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 {
+ println(x, y)
+ panic("bad map")
+ }
+ }
+ {
+ type T [1000]byte
+ type V [1000]byte
+ m := make(map[T]V)
+ m[T{}] = V{1}
+ m[T{1}] = V{2}
+ if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 {
+ println(x, y)
+ panic("bad map")
+ }
+ }
+ {
+ type T [200]byte
+ type V [1]byte
+ m := make(map[T]V)
+ m[T{}] = V{1}
+ m[T{1}] = V{2}
+ if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 {
+ println(x, y)
+ panic("bad map")
+ }
+ }
+ {
+ type T [1]byte
+ type V [200]byte
+ m := make(map[T]V)
+ m[T{}] = V{1}
+ m[T{1}] = V{2}
+ if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 {
+ println(x, y)
+ panic("bad map")
+ }
+ }
+ {
+ type T [200]byte
+ type V [200]byte
+ m := make(map[T]V)
+ m[T{}] = V{1}
+ m[T{1}] = V{2}
+ if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 {
+ println(x, y)
+ panic("bad map")
+ }
+ }
}