Using all values in as_map/as_hashmap

map

#1

I want to use/store all the as_map/as_hashmap keys and their corresponding values in my client program. I’ve not been able to find a function using which I can iteratively go through all the keys/values in the as_map/as_hashmap. Please help.


#2

There is as_map_foreach() and as_map_iterator_init().

See https://github.com/aerospike/aerospike-client-c/blob/bda70092be0b3e14c24b4debe96dd52f45c2a485/src/test/aerospike_udf/udf_types.c#L249


#3
as_hashmap_iterator it;
as_hashmap_iterator_init(&it, &map);
while ( as_hashmap_iterator_has_next(&it) )
 {
    const as_val * val = as_hashmap_iterator_next(&it);
        }

How will I get the map’s key and value from as_val? Are there any functions like as_map_get_key(iterator) and as_map_get_value(iterator)?


#4

You cast it to (as_pair*). See https://github.com/aerospike/aerospike-client-c/blob/bda70092be0b3e14c24b4debe96dd52f45c2a485/src/test/aerospike_udf/udf_types.c#L427


#5

Thanks a lot! This looks like exactly what I wanted. Will try this method today.


#6

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.