The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Path-compressed prefix tries. More...
#include <freeradius-devel/util/dict.h>
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/syserror.h>
#include <freeradius-devel/util/trie.h>
Go to the source code of this file.
Data Structures | |
struct | fr_trie_callback_s |
struct | fr_trie_ctx_t |
struct | fr_trie_node_t |
struct | fr_trie_path_t |
struct | fr_trie_s |
struct | fr_trie_user_t |
Macros | |
#define | BITSOF(_x) ((_x) * 8) |
#define | BYTEOF(_x) ((_x) >> 3) |
#define | BYTES(_x) (((_x) + 0x07) >> 3) |
#define | FR_TRIE_MAX (FR_TRIE_NODE + 1) |
#define | MAX_KEY_BITS (MAX_KEY_BYTES * 8) |
#define | MAX_KEY_BYTES (256) |
#define | MAX_NODE_BITS (4) |
#define | MPRINT(...) |
Internal sanity checks for debugging. More... | |
#define | MPRINT2(...) |
#define | MPRINT3(...) |
#define | trie_check(_trie, _key, _start_bit, _end_bit, _data, _lineno) |
#define | TRIE_HEADER uint8_t type; uint8_t bits |
#define | trie_sprint(_trie, _key, _start_bit, _lineno) |
#define | TRIE_TYPE_CHECK(_x, _r) |
#define | VERIFY(_x) |
#define | WITH_PATH_COMPRESSION |
Enable path compression (or not) More... | |
Typedefs | |
typedef struct fr_trie_callback_s | fr_trie_callback_t |
typedef int(* | fr_trie_key_walk_t) (fr_trie_t *trie, fr_trie_callback_t *cb, int depth, bool more) |
typedef enum fr_trie_type_t | fr_trie_type_t |
typedef int(* | trie_key_insert_t) (TALLOC_CTX *ctx, fr_trie_t **trie_p, uint8_t const *key, int start_bit, int end_bit, void *data) |
typedef void *(* | trie_key_match_t) (fr_trie_t *trie, uint8_t const *key, int start_bit, int end_bit, bool exact) |
typedef void *(* | trie_key_remove_t) (TALLOC_CTX *ctx, fr_trie_t **trie_p, uint8_t const *key, int start_bit, int end_bit) |
Enumerations | |
enum | fr_trie_type_t { FR_TRIE_INVALID = 0 , FR_TRIE_USER , FR_TRIE_PATH , FR_TRIE_NODE } |
Functions | |
static int | _trie_user_cb (fr_trie_t *trie, fr_trie_callback_t *cb, int keylen, UNUSED bool more) |
Implement the user-visible side of the walk callback. More... | |
CC_NO_UBSAN (function) | |
Find an element in the trie, returning the data. More... | |
fr_trie_t * | fr_trie_alloc (TALLOC_CTX *ctx, fr_trie_key_t get_key, fr_free_t free_data) |
Allocate a trie. More... | |
int | fr_trie_insert_by_key (fr_trie_t *ft, void const *key, size_t keylen, void const *data) |
Insert a key and user ctx into a trie. More... | |
static int | fr_trie_key_lcp (uint8_t const *key1, int keylen1, uint8_t const *key2, int keylen2, int start_bit) |
Get the longest prefix of the two keys. More... | |
void * | fr_trie_lookup_by_key (fr_trie_t const *ft, void const *key, size_t keylen) |
Lookup a key in a trie and return user ctx, if any. More... | |
void * | fr_trie_match_by_key (fr_trie_t const *ft, void const *key, size_t keylen) |
Match a key and length in a trie and return user ctx, if any. More... | |
static fr_trie_path_t * | fr_trie_path_alloc (TALLOC_CTX *ctx, uint8_t const *key, int start_bit, int end_bit) |
void * | fr_trie_remove_by_key (fr_trie_t *ft, void const *key, size_t keylen) |
Remove a key and return the associated user ctx. More... | |
static fr_trie_user_t * | fr_trie_user_alloc (TALLOC_CTX *ctx, void const *data) |
int | fr_trie_walk (fr_trie_t *ft, void *ctx, fr_trie_walk_t callback) |
static uint16_t | get_chunk (uint8_t const *key, uint32_t start_bit, uint32_t num_bits) |
Return a chunk of a key (in the low bits) for use in 2^N node de-indexing. More... | |
static int | trie_add_edge (fr_trie_t *trie, uint16_t chunk, fr_trie_t *child) |
Add an edge to a node. More... | |
static void | trie_free (fr_trie_t *trie) |
Free a fr_trie_t. More... | |
static fr_trie_t * | trie_key_alloc (TALLOC_CTX *ctx, uint8_t const *key, int start_bit, int end_bit, void *data) |
static int | trie_key_insert (TALLOC_CTX *ctx, fr_trie_t **trie_p, uint8_t const *key, int start_bit, int end_bit, void *data) |
Insert a binary key into the trie. More... | |
static void * | trie_key_match (fr_trie_t *trie, uint8_t const *key, int start_bit, int end_bit, bool exact) |
Match a key in a trie and return user ctx, if any. More... | |
static void * | trie_key_remove (TALLOC_CTX *ctx, fr_trie_t **trie_p, uint8_t const *key, int start_bit, int end_bit) |
Remove a key from a trie, and return the user data. More... | |
static int | trie_key_walk (fr_trie_t *trie, fr_trie_callback_t *cb, int depth, bool more) |
static fr_trie_node_t * | trie_node_alloc (TALLOC_CTX *ctx, int bits) |
static int | trie_node_insert (TALLOC_CTX *ctx, fr_trie_t **trie_p, uint8_t const *key, int start_bit, int end_bit, void *data) |
static void * | trie_node_match (fr_trie_t *trie, uint8_t const *key, int start_bit, int end_bit, bool exact) |
static void * | trie_node_remove (TALLOC_CTX *ctx, fr_trie_t **trie_p, uint8_t const *key, int start_bit, int end_bit) |
static fr_trie_node_t * | trie_node_split (TALLOC_CTX *ctx, fr_trie_node_t *node, int bits) |
Split a node at bits. More... | |
static int | trie_node_walk (fr_trie_t *trie, fr_trie_callback_t *cb, int depth, bool more) |
static int | trie_path_insert (TALLOC_CTX *ctx, fr_trie_t **trie_p, uint8_t const *key, int start_bit, int end_bit, void *data) |
static void * | trie_path_match (fr_trie_t *trie, uint8_t const *key, int start_bit, int end_bit, bool exact) |
static void * | trie_path_remove (TALLOC_CTX *ctx, fr_trie_t **trie_p, uint8_t const *key, int start_bit, int end_bit) |
static fr_trie_path_t * | trie_path_split (TALLOC_CTX *ctx, fr_trie_path_t *path, int start_bit, int lcp) |
static int | trie_path_walk (fr_trie_t *trie, fr_trie_callback_t *cb, int depth, bool more) |
static int | trie_user_insert (TALLOC_CTX *ctx, fr_trie_t **trie_p, uint8_t const *key, int start_bit, int end_bit, void *data) |
static void * | trie_user_match (fr_trie_t *trie, uint8_t const *key, int start_bit, int end_bit, bool exact) |
static void * | trie_user_remove (TALLOC_CTX *ctx, fr_trie_t **trie_p, uint8_t const *key, int start_bit, int end_bit) |
static int | trie_user_walk (fr_trie_t *trie, fr_trie_callback_t *cb, int depth, bool more) |
static void | write_chunk (uint8_t *out, int start_bit, int num_bits, uint16_t chunk) |
Write a chunk to an output buffer. More... | |
Variables | |
static uint8_t | start_bit_mask [8] |
static trie_key_insert_t | trie_insert_table [FR_TRIE_MAX] |
static trie_key_match_t | trie_match_table [FR_TRIE_MAX] |
static trie_key_remove_t | trie_remove_table [FR_TRIE_MAX] |
static fr_trie_key_walk_t | trie_walk_table [FR_TRIE_MAX] |
static uint8_t | used_bit_mask [8] |
static uint8_t | xor2lcp [256] |
Path-compressed prefix tries.
Definition in file trie.c.
struct fr_trie_callback_s |
Data Fields | ||
---|---|---|
fr_trie_key_walk_t | callback | |
void * | ctx | |
uint8_t const * | end | |
uint8_t * | start | |
fr_trie_walk_t | user_callback |
struct fr_trie_ctx_t |
Data Fields | ||
---|---|---|
uint8_t | buffer[16] | |
fr_free_t | free_data | |
fr_trie_key_t | get_key |
struct fr_trie_node_t |
struct fr_trie_path_t |
struct fr_trie_s |
struct fr_trie_user_t |
#define FR_TRIE_MAX (FR_TRIE_NODE + 1) |
#define MAX_KEY_BITS (MAX_KEY_BYTES * 8) |
#define MPRINT | ( | ... | ) |
Internal sanity checks for debugging.
Tries are complex. So we have verification routines for every type of node. These routines are called from within the trie manipulation functions. If the trie manipulation has a bug, the verification routines are likely to catch some of the more egregious issues.
#define trie_check | ( | _trie, | |
_key, | |||
_start_bit, | |||
_end_bit, | |||
_data, | |||
_lineno | |||
) |
#define WITH_PATH_COMPRESSION |
typedef struct fr_trie_callback_s fr_trie_callback_t |
typedef int(* fr_trie_key_walk_t) (fr_trie_t *trie, fr_trie_callback_t *cb, int depth, bool more) |
typedef enum fr_trie_type_t fr_trie_type_t |
enum fr_trie_type_t |
|
static |
CC_NO_UBSAN | ( | function | ) |
Find an element in the trie, returning the data.
Return how many nodes there are in a trie.
Remove node and free data (if a free function was specified)
Remove an entry, without freeing the data.
Replace old data with new data, OR insert if there is no old.
Insert data into a trie.
Match an element exactly in the trie, returning the data.
[in] | ft | to search in. |
[in] | data | to find. |
[in] | ft | to insert data into. |
[in] | data | to insert. |
[out] | old | data that was replaced. If this argument is not NULL, then the old data will not be freed, even if a free function is configured. |
[in] | ft | to insert data into. |
[in] | data | to replace. |
[in] | ft | to remove data from. |
[in] | data | to remove. |
[in] | ft | to remove data from. |
[in] | data | to remove/free. |
[in] | ft | to return node count for. |
Definition at line 2641 of file trie.c.
fr_trie_t* fr_trie_alloc | ( | TALLOC_CTX * | ctx, |
fr_trie_key_t | get_key, | ||
fr_free_t | free_data | ||
) |
Allocate a trie.
ctx | The talloc ctx. |
get_key | The "get key from object" function. |
free_data | Callback to free data. |
Definition at line 741 of file trie.c.
Insert a key and user ctx into a trie.
ft | the trie |
key | the key |
keylen | key length in bits |
data | user ctx information to associated with the key |
Definition at line 1875 of file trie.c.
Lookup a key in a trie and return user ctx, if any.
The key may be LONGER than entries in the trie. In which case the closest match is returned.
ft | the trie |
key | the key bytes |
keylen | length in bits of the key |
Definition at line 1262 of file trie.c.
Match a key and length in a trie and return user ctx, if any.
Only the exact match is returned.
ft | the trie |
key | the key bytes |
keylen | length in bits of the key |
Definition at line 1286 of file trie.c.
|
static |
|
static |
int fr_trie_walk | ( | fr_trie_t * | ft, |
void * | ctx, | ||
fr_trie_walk_t | callback | ||
) |
|
static |
Free a fr_trie_t.
We can't use talloc_free(), because we can't talloc_parent the nodes from each other, as talloc_steal() is O(N). So, we just recurse manually.
Definition at line 562 of file trie.c.
|
static |
Insert a binary key into the trie.
The key must have at least ((start_bit + keylen) >> 3) bytes
ctx | the talloc ctx | |
[in,out] | trie_p | the trie where things are inserted |
key | the binary key | |
start_bit | the start bit | |
end_bit | the end bit | |
data | user data to insert |
Definition at line 1810 of file trie.c.
|
static |
Match a key in a trie and return user ctx, if any.
The key may be LONGER than entries in the trie. In which case the closest match is returned.
trie | the trie |
key | the key |
start_bit | the start bit |
end_bit | the end bit |
exact | do we return an exact match, or the shortest one. |
Definition at line 1226 of file trie.c.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |