1// run 2 3// Copyright 2009 The Go Authors. All rights reserved. 4// Use of this source code is governed by a BSD-style 5// license that can be found in the LICENSE file. 6 7// Internally a map holds elements in up to 255 bytes of key+value. 8// When key or value or both are too large, it uses pointers to key+value 9// instead. Test all the combinations. 10 11package main 12 13func seq(x, y int) [1000]byte { 14 var r [1000]byte 15 for i := 0; i < len(r); i++ { 16 r[i] = byte(x + i*y) 17 } 18 return r 19} 20 21func cmp(x, y [1000]byte) { 22 for i := 0; i < len(x); i++ { 23 if x[i] != y[i] { 24 panic("BUG mismatch") 25 } 26 } 27} 28 29func main() { 30 m := make(map[int][1000]byte) 31 m[1] = seq(11, 13) 32 m[2] = seq(2, 9) 33 m[3] = seq(3, 17) 34 35 cmp(m[1], seq(11, 13)) 36 cmp(m[2], seq(2, 9)) 37 cmp(m[3], seq(3, 17)) 38 39 40 { 41 type T [1]byte 42 type V [1]byte 43 m := make(map[T]V) 44 m[T{}] = V{1} 45 m[T{1}] = V{2} 46 if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 { 47 println(x, y) 48 panic("bad map") 49 } 50 } 51 { 52 type T [100]byte 53 type V [1]byte 54 m := make(map[T]V) 55 m[T{}] = V{1} 56 m[T{1}] = V{2} 57 if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 { 58 println(x, y) 59 panic("bad map") 60 } 61 } 62 { 63 type T [1]byte 64 type V [100]byte 65 m := make(map[T]V) 66 m[T{}] = V{1} 67 m[T{1}] = V{2} 68 if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 { 69 println(x, y) 70 panic("bad map") 71 } 72 } 73 { 74 type T [1000]byte 75 type V [1]byte 76 m := make(map[T]V) 77 m[T{}] = V{1} 78 m[T{1}] = V{2} 79 if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 { 80 println(x, y) 81 panic("bad map") 82 } 83 } 84 { 85 type T [1]byte 86 type V [1000]byte 87 m := make(map[T]V) 88 m[T{}] = V{1} 89 m[T{1}] = V{2} 90 if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 { 91 println(x, y) 92 panic("bad map") 93 } 94 } 95 { 96 type T [1000]byte 97 type V [1000]byte 98 m := make(map[T]V) 99 m[T{}] = V{1} 100 m[T{1}] = V{2} 101 if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 { 102 println(x, y) 103 panic("bad map") 104 } 105 } 106 { 107 type T [200]byte 108 type V [1]byte 109 m := make(map[T]V) 110 m[T{}] = V{1} 111 m[T{1}] = V{2} 112 if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 { 113 println(x, y) 114 panic("bad map") 115 } 116 } 117 { 118 type T [1]byte 119 type V [200]byte 120 m := make(map[T]V) 121 m[T{}] = V{1} 122 m[T{1}] = V{2} 123 if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 { 124 println(x, y) 125 panic("bad map") 126 } 127 } 128 { 129 type T [200]byte 130 type V [200]byte 131 m := make(map[T]V) 132 m[T{}] = V{1} 133 m[T{1}] = V{2} 134 if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 { 135 println(x, y) 136 panic("bad map") 137 } 138 } 139} 140