mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-12 08:13:48 +03:00
radix_tree: add radix_tree_lookup/insert_ptr
Add simple 'wrapper' inline functions to insert or return ptr lookup value. (So the user doesn't need to deal with 'union radix_value' locally and also it makes easier to translage some lvm2 functions to use radix_tree). Note: If the stored 'value' would NULL, it cannot be recognized from a case of 'not found'. So usable only when 'values' stored with tree are not NULL.
This commit is contained in:
parent
b77edc337a
commit
1813d0d186
@ -59,6 +59,19 @@ void radix_tree_iterate(struct radix_tree *rt, const void *key, size_t keylen,
|
||||
bool radix_tree_is_well_formed(struct radix_tree *rt);
|
||||
void radix_tree_dump(struct radix_tree *rt, FILE *out);
|
||||
|
||||
// Shortcut for ptr value return
|
||||
// Note: if value would be NULL, it's same result for not/found case.
|
||||
static inline void *radix_tree_lookup_ptr(struct radix_tree *rt, const void *key, size_t keylen)
|
||||
{
|
||||
union radix_value v;
|
||||
return radix_tree_lookup(rt, key, keylen, &v) ? v.ptr : NULL;
|
||||
}
|
||||
|
||||
static inline bool radix_tree_insert_ptr(struct radix_tree *rt, const void *key, size_t keylen, void *ptr)
|
||||
{
|
||||
union radix_value v = { .ptr = ptr };
|
||||
return radix_tree_insert(rt, key, keylen, v);
|
||||
}
|
||||
//----------------------------------------------------------------
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user