MapForeachValueForKey
Description
Iterate over all values stored for a specific key.
Parameters
| Name | Direction | Description |
|---|---|---|
m |
in,out | Map to iterate over. |
lookup_key |
in | Key value to match against (compared via the map’s key_compare callback). |
value_var |
in | Name of variable bound to a copy of each matching stored value. |
Success
The loop body runs once for each value stored under lookup_key, with value_var bound to a copy of that value. The body is skipped when m is empty or when the key is not present.
Failure
The macro itself does not fail. LOG_FATAL via ValidateMap(m) when m is uninitialised or corrupted.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Map.Foreach.c:67:
}
MapForeachValueForKey(&map, 2, value) {
key_two_sum += value;
}- In
Map.Ops.c:58:
stored_value = MapGetFirstPtr(&map, "alpha");
result = result && stored_value && (*stored_value != value) && (ZstrCompare(*stored_value, "first") == 0);
MapForeachValueForKey(&map, "alpha", entry_value) {
if ((ZstrCompare(entry_value, "first") == 0) || (ZstrCompare(entry_value, "second") == 0)) {
value_count += 1;- In
Map.Ops.c:99:
result = result && MapGetFirstPtr(&map, "yellow") && (ZstrCompare(*MapGetFirstPtr(&map, "yellow"), "banana") == 0);
result = result && MapGetFirstPtr(&map, "green") && (ZstrCompare(*MapGetFirstPtr(&map, "green"), "pear") == 0);
MapForeachValueForKey(&map, "red", red_value) {
if ((ZstrCompare(red_value, "apple") == 0) || (ZstrCompare(red_value, "cherry") == 0)) {
red_count += 1;
Last updated on