]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgo/runtime/map.goc
Add Go frontend, libgo library, and Go testsuite.
[thirdparty/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 hmap;
13 typedef struct __go_hash_iter hiter;
14
15 /* Access a value in a map, returning a value and a presence indicator. */
16
17 func mapaccess2(h *hmap, key *byte, val *byte) (present bool) {
18 byte *mapval;
19 size_t valsize;
20
21 mapval = __go_map_index(h, key, 0);
22 valsize = h->__descriptor->__map_descriptor->__val_type->__size;
23 if (mapval == nil) {
24 __builtin_memset(val, 0, valsize);
25 present = 0;
26 } else {
27 __builtin_memcpy(val, mapval, valsize);
28 present = 1;
29 }
30 }
31
32 /* Optionally assign a value to a map (m[k] = v, p). */
33
34 func mapassign2(h *hmap, key *byte, val *byte, p bool) {
35 if (!p) {
36 __go_map_delete(h, key);
37 } else {
38 byte *mapval;
39 size_t valsize;
40
41 mapval = __go_map_index(h, key, 1);
42 valsize = h->__descriptor->__map_descriptor->__val_type->__size;
43 __builtin_memcpy(mapval, val, valsize);
44 }
45 }
46
47 /* Initialize a range over a map. */
48
49 func mapiterinit(h *hmap, it *hiter) {
50 __go_mapiterinit(h, it);
51 }
52
53 /* Move to the next iteration, updating *HITER. */
54
55 func mapiternext(it *hiter) {
56 __go_mapiternext(it);
57 }
58
59 /* Get the key of the current iteration. */
60
61 func mapiter1(it *hiter, key *byte) {
62 __go_mapiter1(it, key);
63 }
64
65 /* Get the key and value of the current iteration. */
66
67 func mapiter2(it *hiter, key *byte, val *byte) {
68 __go_mapiter2(it, key, val);
69 }