Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Functions | Variables
astobj2_hash.c File Reference

Hash table functions implementing astobj2 containers. More...

#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/astobj2.h"
#include "astobj2_private.h"
#include "astobj2_container_private.h"
#include "asterisk/dlinkedlists.h"
#include "asterisk/utils.h"

Go to the source code of this file.

Data Structures

struct  ao2_container_hash
 
struct  hash_bucket
 
struct  hash_bucket_node
 
struct  hash_traversal_state
 
struct  hash_traversal_state_check
 

Functions

struct ao2_container__ao2_container_alloc_hash (unsigned int ao2_options, unsigned int container_options, unsigned int n_buckets, ao2_hash_fn *hash_fn, ao2_sort_fn *sort_fn, ao2_callback_fn *cmp_fn, const char *tag, const char *file, int line, const char *func)
 
struct ao2_container__ao2_container_alloc_list (unsigned int ao2_options, unsigned int container_options, ao2_sort_fn *sort_fn, ao2_callback_fn *cmp_fn, const char *tag, const char *file, int line, const char *func)
 
static struct ao2_containerhash_ao2_alloc_empty_clone (struct ao2_container_hash *self, const char *tag, const char *file, int line, const char *func)
 
static struct ao2_containerhash_ao2_container_init (struct ao2_container_hash *self, unsigned int options, unsigned int n_buckets, ao2_hash_fn *hash_fn, ao2_sort_fn *sort_fn, ao2_callback_fn *cmp_fn)
 Initialize a hash container with the desired number of buckets. More...
 
static void hash_ao2_destroy (struct ao2_container_hash *self)
 
static struct hash_bucket_nodehash_ao2_find_first (struct ao2_container_hash *self, enum search_flags flags, void *arg, struct hash_traversal_state *state)
 
static struct hash_bucket_nodehash_ao2_find_next (struct ao2_container_hash *self, struct hash_traversal_state *state, struct hash_bucket_node *prev)
 
static enum ao2_container_insert hash_ao2_insert_node (struct ao2_container_hash *self, struct hash_bucket_node *node)
 
static struct hash_bucket_nodehash_ao2_iterator_next (struct ao2_container_hash *self, struct hash_bucket_node *node, enum ao2_iterator_flags flags)
 
static struct hash_bucket_nodehash_ao2_new_node (struct ao2_container_hash *self, void *obj_new, const char *tag, const char *file, int line, const char *func)
 
static void hash_ao2_node_destructor (void *v_doomed)
 
static int hash_zero (const void *user_obj, const int flags)
 always zero hash function More...
 

Variables

static const struct ao2_container_methods v_table_hash
 

Detailed Description

Hash table functions implementing astobj2 containers.

Author
Richard Mudgett rmudg.nosp@m.ett@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file astobj2_hash.c.

Function Documentation

static struct ao2_container* hash_ao2_container_init ( struct ao2_container_hash self,
unsigned int  options,
unsigned int  n_buckets,
ao2_hash_fn hash_fn,
ao2_sort_fn sort_fn,
ao2_callback_fn cmp_fn 
)
static

Initialize a hash container with the desired number of buckets.

Parameters
selfContainer to initialize.
optionsContainer behaviour options (See enum ao2_container_opts)
n_bucketsNumber of buckets for hash
hash_fnPointer to a function computing a hash value.
sort_fnPointer to a sort function.
cmp_fnPointer to a compare function used by ao2_find.
Returns
A pointer to a struct container.

Definition at line 1045 of file astobj2_hash.c.

References ast_atomic_fetchadd_int(), ao2_container::cmp_fn, hash_zero(), ao2_container::options, ao2_container::sort_fn, and v_table_hash.

1048 {
1049  if (!self) {
1050  return NULL;
1051  }
1052 
1053  self->common.v_table = &v_table_hash;
1054  self->common.sort_fn = sort_fn;
1055  self->common.cmp_fn = cmp_fn;
1056  self->common.options = options;
1057  self->hash_fn = hash_fn ? hash_fn : hash_zero;
1058  self->n_buckets = n_buckets;
1059 
1060 #ifdef AO2_DEBUG
1061  ast_atomic_fetchadd_int(&ao2.total_containers, 1);
1062 #endif /* defined(AO2_DEBUG) */
1063 
1064  return (struct ao2_container *) self;
1065 }
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:757
static int hash_zero(const void *user_obj, const int flags)
always zero hash function
static const struct ao2_container_methods v_table_hash
Generic container type.
ao2_callback_fn * cmp_fn
static int hash_zero ( const void *  user_obj,
const int  flags 
)
static

always zero hash function

it is convenient to have a hash function that always returns 0. This is basically used when we want to have a container that is a simple linked list.

Return values
0

Definition at line 1028 of file astobj2_hash.c.

Referenced by hash_ao2_container_init().

1029 {
1030  return 0;
1031 }

Variable Documentation

const struct ao2_container_methods v_table_hash
static

Hash container virtual method table.

Definition at line 1002 of file astobj2_hash.c.

Referenced by hash_ao2_container_init().