Example #1
0
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;
}
Example #2
0
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;
}
Example #3
0
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;
}
Example #4
0
	void skiplist<K, V>::remove(K key) {
		find_node_ptr(key, true, false, nullptr);
	}
Example #5
0
	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");
	}
Example #6
0
	void skiplist<K, V>::insert(K key, V value) {
		find_node_ptr(key, false, true, &value);
	}
Example #7
0
	bool skiplist<K, V>::find(K key) {
		node* res = find_node_ptr(key, false, false, nullptr);
		return res != nullptr;
	}