cf_map_swap¶
Category: map
GitHub: cute_map.h
Swaps two {key, item} pairs by index without breaking the hash lookup.
| Parameters | Description |
|---|---|
m |
The map. Can be NULL. Must be declared with CF_MAP(T). |
index_a |
Index of the first item to swap. |
index_b |
Index of the second item to swap. |
Code Example¶
Swap elements during iteration (e.g., for custom sorting).
CF_MAP(CF_V2) table = my_table();
for (int i = 0; i < map_size(table); ++i) {
for (int j = i + 1; j < map_size(table); ++j) {
if (my_need_swap(table, i, j)) {
map_swap(table, i, j);
}
}
}
Remarks¶
Use this for implementing priority queues or custom sort orders on top of the map.
Related Pages¶
CF_MAP
cf_map_sort
cf_map_ssort
cf_map_keys
cf_map_items
cf_map_size