avl_node * avl_finder(void * key, avl_node * node, int (*cmp_keys)(void * a, void * b)) { if (node == NULL || cmp_keys(node->key, key) == 0) { return node; } else if (cmp_keys(key, node->key) < 0) { return avl_finder(key, node->left, cmp_keys); } else { return avl_finder(key, node->right, cmp_keys); } }
rv_map_item* rv_map_at(rv_map *map, char *key) { RV_CHECK(map); RV_CHECK(key); rv_map_slot *slot = map->root + get_slot_index(map, key); rv_map_item *cur = slot->first; rv_map_item *last = cur; rv_map_item *item; if (cur) { while (cur) { if (cmp_keys(cur->key, key)) return cur; last = cur; cur = cur->next; } } // key not exist, create a new item item = (rv_map_item*)rv_malloc(sizeof(rv_map_item)); item->key = rv_strdup(key); // initialize value, set to NULL item->value = NULL; item->next = NULL; item->prev = last; last->next = item; map->count++; return item; }
PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC bool PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC:: operator()(const_key_reference r_lhs, const_key_reference r_rhs) { return (cmp_keys(r_lhs, r_rhs)); }
rv_map_item* rv_map_get(rv_map *map, char *key) { RV_CHECK(map); RV_CHECK(key); rv_map_item *cur = (map->root + get_slot_index(map, key))->first; while (cur) { if (cmp_keys(cur->key, key)) return cur; cur = cur->next; } return NULL; }
bool rv_map_contains(rv_map *map, char *key) { RV_CHECK(map); RV_CHECK(key); rv_map_item *cur = (map->root + get_slot_index(map, key))->first; while (cur) { if (cmp_keys(cur->key, key)) return true; cur = cur->next; } return false; }