2008-12-06 02:24:05 +00:00
|
|
|
// $G $D/$F.go && $L $F.$A && ./$A.out
|
|
|
|
|
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
const size = 16;
|
|
|
|
|
|
|
|
var a [size]byte;
|
2008-12-19 04:06:28 +00:00
|
|
|
var p []byte;
|
2008-12-19 11:05:37 +00:00
|
|
|
var m map[int]byte;
|
2008-12-06 02:24:05 +00:00
|
|
|
|
|
|
|
func
|
|
|
|
f(k int) byte
|
|
|
|
{
|
|
|
|
return byte(k*10007 % size);
|
|
|
|
}
|
|
|
|
|
|
|
|
func
|
|
|
|
init()
|
|
|
|
{
|
2009-01-06 23:19:02 +00:00
|
|
|
p = make([]byte, size);
|
|
|
|
m = make(map[int]byte);
|
2008-12-06 02:24:05 +00:00
|
|
|
for k:=0; k<size; k++ {
|
|
|
|
v := f(k);
|
|
|
|
a[k] = v;
|
|
|
|
p[k] = v;
|
|
|
|
m[k] = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
var i int;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* key only
|
|
|
|
*/
|
|
|
|
i = 0;
|
2008-12-15 21:44:27 +00:00
|
|
|
for k := range a {
|
2008-12-06 02:24:05 +00:00
|
|
|
v := a[k];
|
|
|
|
if v != f(k) {
|
|
|
|
panicln("key array range", k, v, a[k]);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if i != size {
|
|
|
|
panicln("key array size", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
2008-12-15 21:44:27 +00:00
|
|
|
for k := range p {
|
2008-12-06 02:24:05 +00:00
|
|
|
v := p[k];
|
|
|
|
if v != f(k) {
|
|
|
|
panicln("key pointer range", k, v, p[k]);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if i != size {
|
|
|
|
panicln("key pointer size", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
2008-12-15 21:44:27 +00:00
|
|
|
for k := range m {
|
2008-12-06 02:24:05 +00:00
|
|
|
v := m[k];
|
|
|
|
if v != f(k) {
|
|
|
|
panicln("key map range", k, v, m[k]);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if i != size {
|
|
|
|
panicln("key map size", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-01-26 19:34:38 +00:00
|
|
|
* key,value
|
2008-12-06 02:24:05 +00:00
|
|
|
*/
|
|
|
|
i = 0;
|
2009-01-26 19:34:38 +00:00
|
|
|
for k,v := range a {
|
2008-12-06 02:24:05 +00:00
|
|
|
if v != f(k) {
|
|
|
|
panicln("key:value array range", k, v, a[k]);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if i != size {
|
|
|
|
panicln("key:value array size", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
2009-01-26 19:34:38 +00:00
|
|
|
for k,v := range p {
|
2008-12-06 02:24:05 +00:00
|
|
|
if v != f(k) {
|
|
|
|
panicln("key:value pointer range", k, v, p[k]);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if i != size {
|
|
|
|
panicln("key:value pointer size", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
2009-01-26 19:34:38 +00:00
|
|
|
for k,v := range m {
|
2008-12-06 02:24:05 +00:00
|
|
|
if v != f(k) {
|
|
|
|
panicln("key:value map range", k, v, m[k]);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if i != size {
|
|
|
|
panicln("key:value map size", i);
|
|
|
|
}
|
|
|
|
}
|