Fix r180999.
[gcc.git] / libgo / runtime / map.goc
1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package runtime
6 #include "map.h"
7 #define nil NULL
8
9 typedef unsigned char byte;
10 typedef _Bool bool;
11
12 typedef struct __go_map_type MapType;
13 typedef struct __go_map Hmap;
14 typedef struct __go_hash_iter hiter;
15
16 /* Access a value in a map, returning a value and a presence indicator. */
17
18 func mapaccess2(t *MapType, h *Hmap, key *byte, val *byte) (present bool) {
19 byte *mapval;
20 size_t valsize;
21
22 mapval = __go_map_index(h, key, 0);
23 valsize = t->__val_type->__size;
24 if (mapval == nil) {
25 __builtin_memset(val, 0, valsize);
26 present = 0;
27 } else {
28 __builtin_memcpy(val, mapval, valsize);
29 present = 1;
30 }
31 }
32
33 /* Optionally assign a value to a map (m[k] = v, p). */
34
35 func mapassign2(h *Hmap, key *byte, val *byte, p bool) {
36 if (!p) {
37 __go_map_delete(h, key);
38 } else {
39 byte *mapval;
40 size_t valsize;
41
42 mapval = __go_map_index(h, key, 1);
43 valsize = h->__descriptor->__map_descriptor->__val_type->__size;
44 __builtin_memcpy(mapval, val, valsize);
45 }
46 }
47
48 /* Delete a key from a map. */
49
50 func mapdelete(h *Hmap, key *byte) {
51 __go_map_delete(h, key);
52 }
53
54 /* Initialize a range over a map. */
55
56 func mapiterinit(h *Hmap, it *hiter) {
57 __go_mapiterinit(h, it);
58 }
59
60 /* Move to the next iteration, updating *HITER. */
61
62 func mapiternext(it *hiter) {
63 __go_mapiternext(it);
64 }
65
66 /* Get the key of the current iteration. */
67
68 func mapiter1(it *hiter, key *byte) {
69 __go_mapiter1(it, key);
70 }
71
72 /* Get the key and value of the current iteration. */
73
74 func mapiter2(it *hiter, key *byte, val *byte) {
75 __go_mapiter2(it, key, val);
76 }