void * ep_hash_delete( EP_HASH *hp, size_t keylen, const void *key) { struct node **npp; struct node *n; void *v; EP_ASSERT_POINTER_VALID(hp); ep_thr_mutex_lock(&hp->mutex); npp = find_node_ptr(hp, keylen, key); if (*npp == NULL) { // entry does not exist ep_thr_mutex_unlock(&hp->mutex); return NULL; } n = *npp; v = n->val; n->val = NULL; // since ep_rpool_mfree doesn't free yet, leave this node in // the list to allow re-use of the key without losing more memory //*npp = n->next; //ep_rpool_mfree(hp->rpool, n->key); //ep_rpool_mfree(hp->rpool, n); ep_thr_mutex_unlock(&hp->mutex); return v; }
void * ep_hash_search( EP_HASH *hp, size_t keylen, const void *key) { struct node **npp; void *val; EP_ASSERT_POINTER_VALID(hp); ep_thr_mutex_lock(&hp->mutex); npp = find_node_ptr(hp, keylen, key); if (*npp == NULL) val = NULL; else val = (*npp)->val; ep_thr_mutex_unlock(&hp->mutex); return val; }
void * ep_hash_insert( EP_HASH *hp, size_t keylen, const void *key, void *val) { struct node **npp; struct node *n; void *kp; EP_ASSERT_POINTER_VALID(hp); ep_thr_mutex_lock(&hp->mutex); npp = find_node_ptr(hp, keylen, key); if (*npp != NULL) { // there is an existing value; replace it void *oldval; n = *npp; oldval = n->val; n->val = val; ep_thr_mutex_unlock(&hp->mutex); return oldval; } // not found -- insert it n = ep_rpool_malloc(hp->rpool, sizeof *n); n->keylen = keylen; kp = ep_rpool_malloc(hp->rpool, keylen); memcpy(kp, key, keylen); n->key = kp; n->val = val; n->next = NULL; *npp = n; ep_thr_mutex_unlock(&hp->mutex); return NULL; }
void skiplist<K, V>::remove(K key) { find_node_ptr(key, true, false, nullptr); }
V& skiplist<K, V>::get(K key) { node* res = find_node_ptr(key, false, false, nullptr); if(res) return res->value; throw std::invalid_argument("Key not found"); }
void skiplist<K, V>::insert(K key, V value) { find_node_ptr(key, false, true, &value); }
bool skiplist<K, V>::find(K key) { node* res = find_node_ptr(key, false, false, nullptr); return res != nullptr; }