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. */
11 /* Initialize a range over a map. */
14 __go_mapiterinit (const struct __go_map
*h
, struct __go_hash_iter
*it
)
20 it
->next_entry
= NULL
;
27 /* Move to the next iteration, updating *HITER. */
30 __go_mapiternext (struct __go_hash_iter
*it
)
34 entry
= it
->next_entry
;
37 const struct __go_map
*map
;
45 if (bucket
>= map
->__bucket_count
)
47 /* Map iteration is complete. */
51 entry
= map
->__buckets
[bucket
];
58 it
->next_entry
= *(const void * const *) entry
;
61 /* Get the key of the current iteration. */
64 __go_mapiter1 (struct __go_hash_iter
*it
, unsigned char *key
)
66 const struct __go_map
*map
;
67 const struct __go_map_descriptor
*descriptor
;
68 const struct __go_type_descriptor
*key_descriptor
;
72 descriptor
= map
->__descriptor
;
73 key_descriptor
= descriptor
->__map_descriptor
->__key_type
;
75 __go_assert (p
!= NULL
);
76 __builtin_memcpy (key
, p
+ descriptor
->__key_offset
, key_descriptor
->__size
);
79 /* Get the key and value of the current iteration. */
82 __go_mapiter2 (struct __go_hash_iter
*it
, unsigned char *key
,
85 const struct __go_map
*map
;
86 const struct __go_map_descriptor
*descriptor
;
87 const struct __go_map_type
*map_descriptor
;
88 const struct __go_type_descriptor
*key_descriptor
;
89 const struct __go_type_descriptor
*val_descriptor
;
93 descriptor
= map
->__descriptor
;
94 map_descriptor
= descriptor
->__map_descriptor
;
95 key_descriptor
= map_descriptor
->__key_type
;
96 val_descriptor
= map_descriptor
->__val_type
;
98 __go_assert (p
!= NULL
);
99 __builtin_memcpy (key
, p
+ descriptor
->__key_offset
,
100 key_descriptor
->__size
);
101 __builtin_memcpy (val
, p
+ descriptor
->__val_offset
,
102 val_descriptor
->__size
);