Exemplo n.º 1
0
/**
 * Internal lookup function. Only wraps #edgehash_lookup_entry_ex
 */
BLI_INLINE EdgeEntry *edgehash_lookup_entry(EdgeHash *eh, unsigned int v0, unsigned int v1)
{
	unsigned int hash;
	EDGE_ORD(v0, v1); /* ensure v0 is smaller */
	hash = edgehash_keyhash(eh, v0, v1);
	return edgehash_lookup_entry_ex(eh, v0, v1, hash);
}
Exemplo n.º 2
0
/**
 * A version of BLI_edgeset_insert which checks first if the key is in the set.
 * \returns true if a new key has been added.
 *
 * \note EdgeHash has no equivalent to this because typically the value would be different.
 */
bool BLI_edgeset_add(EdgeSet *es, uint v0, uint v1)
{
	EDGE_ORD(v0, v1);
	const uint bucket_index = edgehash_bucket_index((EdgeHash *)es, v0, v1);

	EdgeEntry *e = edgehash_lookup_entry_ex((EdgeHash *)es, v0, v1, bucket_index);
	if (e) {
		return false;
	}
	else {
		edgehash_insert_ex_keyonly((EdgeHash *)es, v0, v1, bucket_index);
		return true;
	}
}
Exemplo n.º 3
0
/**
 * Ensure \a (v0, v1) is exists in \a eh.
 *
 * This handles the common situation where the caller needs ensure a key is added to \a eh,
 * constructing a new value in the case the key isn't found.
 * Otherwise use the existing value.
 *
 * Such situations typically incur multiple lookups, however this function
 * avoids them by ensuring the key is added,
 * returning a pointer to the value so it can be used or initialized by the caller.
 *
 * \returns true when the value didn't need to be added.
 * (when false, the caller _must_ initialize the value).
 */
bool BLI_edgehash_ensure_p(EdgeHash *eh, uint v0, uint v1, void ***r_val)
{
	EDGE_ORD(v0, v1);
	const uint bucket_index = edgehash_bucket_index(eh, v0, v1);
	EdgeEntry *e = edgehash_lookup_entry_ex(eh, v0, v1, bucket_index);
	const bool haskey = (e != NULL);

	if (!haskey) {
		e = BLI_mempool_alloc(eh->epool);
		edgehash_insert_ex_keyonly_entry(eh, v0, v1, bucket_index, e);
	}

	*r_val = &e->val;
	return haskey;
}
Exemplo n.º 4
0
/**
 * Assign a new value to a key that may already be in edgehash.
 */
bool BLI_edgeset_reinsert(EdgeSet *es, unsigned int v0, unsigned int v1)
{
	unsigned int hash;
	EdgeEntry *e;

	EDGE_ORD(v0, v1); /* ensure v0 is smaller */
	hash = edgehash_keyhash((EdgeHash *)es, v0, v1);

	e = edgehash_lookup_entry_ex((EdgeHash *)es, v0, v1, hash);
	if (e) {
		return false;
	}
	else {
		edgehash_insert_ex_keyonly((EdgeHash *)es, v0, v1, hash);
		return true;
	}
}
Exemplo n.º 5
0
/**
 * Assign a new value to a key that may already be in edgehash.
 */
bool BLI_edgehash_reinsert(EdgeHash *eh, uint v0, uint v1, void *val)
{
	IS_EDGEHASH_ASSERT(eh);

	EDGE_ORD(v0, v1);
	const uint bucket_index = edgehash_bucket_index(eh, v0, v1);

	EdgeEntry *e = edgehash_lookup_entry_ex(eh, v0, v1, bucket_index);
	if (e) {
		e->val = val;
		return false;
	}
	else {
		edgehash_insert_ex(eh, v0, v1, val, bucket_index);
		return true;
	}
}
Exemplo n.º 6
0
/**
 * Assign a new value to a key that may already be in edgehash.
 */
bool BLI_edgehash_reinsert(EdgeHash *eh, unsigned int v0, unsigned int v1, void *val)
{
	unsigned int hash;
	EdgeEntry *e;

	IS_EDGEHASH_ASSERT(eh);

	EDGE_ORD(v0, v1); /* ensure v0 is smaller */
	hash = edgehash_keyhash(eh, v0, v1);

	e = edgehash_lookup_entry_ex(eh, v0, v1, hash);
	if (e) {
		e->val = val;
		return false;
	}
	else {
		edgehash_insert_ex(eh, v0, v1, val, hash);
		return true;
	}
}
Exemplo n.º 7
0
/**
 * Internal lookup function. Only wraps #edgehash_lookup_entry_ex
 */
BLI_INLINE EdgeEntry *edgehash_lookup_entry(EdgeHash *eh, uint v0, uint v1)
{
	EDGE_ORD(v0, v1);
	const uint bucket_index = edgehash_bucket_index(eh, v0, v1);
	return edgehash_lookup_entry_ex(eh, v0, v1, bucket_index);
}