]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add match() API
authorAlan T. DeKok <aland@freeradius.org>
Mon, 26 Apr 2021 19:17:55 +0000 (15:17 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 26 Apr 2021 19:17:55 +0000 (15:17 -0400)
src/lib/util/htrie.c
src/lib/util/htrie.h

index 4b2f5d2225c0e4eb04df5c8215c14ffdb479911c..41b5b0fb6fe172ad88ad308f4411476b4adbea6a 100644 (file)
@@ -28,6 +28,7 @@ RCSID("$Id$")
 
 static fr_htrie_funcs_t const default_funcs[] = {
        [FR_HTRIE_HASH] = {
+               .match = (fr_htrie_find_t) fr_hash_table_find,
                FUNC(hash_table, find),
                FUNC(hash_table, insert),
                FUNC(hash_table, replace),
@@ -36,6 +37,7 @@ static fr_htrie_funcs_t const default_funcs[] = {
                FUNC(hash_table, num_elements)
        },
        [FR_HTRIE_RB] = {
+               .match = (fr_htrie_find_t) fr_rb_find,
                FUNC(rb, find),
                FUNC(rb, insert),
                FUNC(rb, replace),
@@ -44,6 +46,7 @@ static fr_htrie_funcs_t const default_funcs[] = {
                FUNC(rb, num_elements)
        },
        [FR_HTRIE_TRIE] = {
+               .match = (fr_htrie_find_t) fr_trie_match,
                FUNC(trie, find),
                FUNC(trie, insert),
                FUNC(trie, replace),
index da723844114044bacf7dd34a11f8bf67ad120f7e..68396e9292eaed4064a9affd1f7b484f3771b352 100644 (file)
@@ -51,6 +51,7 @@ typedef uint32_t (*fr_htrie_num_elements_t)(fr_htrie_t *ht);
  */
 typedef struct {
        fr_htrie_find_t         find;           //!< Absolute or prefix match.
+       fr_htrie_find_t         match;          //!< exact prefix match
        fr_htrie_insert_t       insert;         //!< Insert a new item into the store.
        fr_htrie_replace_t      replace;        //!< Replace an existing item in store.
        fr_htrie_remove_t       remove;         //!< Remove an item from the store.
@@ -80,6 +81,14 @@ fr_htrie_t *fr_htrie_alloc(TALLOC_CTX *ctx,
                           fr_trie_key_t get_key,
                           fr_free_t free_data);
 
+/** Match data in a htrie
+ *
+ */
+static inline CC_HINT(nonnull) void *fr_htrie_match(fr_htrie_t *ht, void const *data)
+{
+       return ht->funcs.match(ht->store, data);
+}
+
 /** Find data in a htrie
  *
  */