1 /* go-map-range.c -- implement a range clause over a map.
3 Copyright 2009, 2010 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. */
10 /* Initialize a range over a map. */
13 __go_mapiterinit (const struct __go_map
*h
, struct __go_hash_iter
*it
)
19 it
->next_entry
= NULL
;
26 /* Move to the next iteration, updating *HITER. */
29 __go_mapiternext (struct __go_hash_iter
*it
)
33 entry
= it
->next_entry
;
36 const struct __go_map
*map
;
44 if (bucket
>= map
->__bucket_count
)
46 /* Map iteration is complete. */
50 entry
= map
->__buckets
[bucket
];
57 it
->next_entry
= *(const void * const *) entry
;
60 /* Get the key of the current iteration. */
63 __go_mapiter1 (struct __go_hash_iter
*it
, unsigned char *key
)
65 const struct __go_map
*map
;
66 const struct __go_map_descriptor
*descriptor
;
67 const struct __go_type_descriptor
*key_descriptor
;
71 descriptor
= map
->__descriptor
;
72 key_descriptor
= descriptor
->__map_descriptor
->__key_type
;
74 __go_assert (p
!= NULL
);
75 __builtin_memcpy (key
, p
+ descriptor
->__key_offset
, key_descriptor
->__size
);
78 /* Get the key and value of the current iteration. */
81 __go_mapiter2 (struct __go_hash_iter
*it
, unsigned char *key
,
84 const struct __go_map
*map
;
85 const struct __go_map_descriptor
*descriptor
;
86 const struct __go_map_type
*map_descriptor
;
87 const struct __go_type_descriptor
*key_descriptor
;
88 const struct __go_type_descriptor
*val_descriptor
;
92 descriptor
= map
->__descriptor
;
93 map_descriptor
= descriptor
->__map_descriptor
;
94 key_descriptor
= map_descriptor
->__key_type
;
95 val_descriptor
= map_descriptor
->__val_type
;
97 __go_assert (p
!= NULL
);
98 __builtin_memcpy (key
, p
+ descriptor
->__key_offset
,
99 key_descriptor
->__size
);
100 __builtin_memcpy (val
, p
+ descriptor
->__val_offset
,
101 val_descriptor
->__size
);