modules/sca/sca_hash.h
ce6a9ca2
 /*
  * Copyright (C) 2012 Andrew Mortensen
  *
313e77d3
  * This file is part of the sca module for Kamailio, a free SIP server.
ce6a9ca2
  *
  * The sca module is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
  * The sca module is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
9e1ff448
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
ce6a9ca2
  *
  *
  */
d694ceba
 #ifndef SCA_HASH_H
 #define SCA_HASH_H
 
 struct _sca_hash_slot;
 struct _sca_hash_entry {
     void			*value;
     int				(*compare)( str *, void * );
     void			(*description)( void * );
     void			(*free_entry)( void * );
     struct _sca_hash_slot	*slot;
     struct _sca_hash_entry	*next;
 };
 typedef struct _sca_hash_entry	sca_hash_entry;
 
 struct _sca_hash_slot {
     gen_lock_t			lock;
     sca_hash_entry		*entries;
 };
 typedef struct _sca_hash_slot	sca_hash_slot;
 
 struct _sca_hash_table {
     unsigned int		size;	/* power of two */
     sca_hash_slot		*slots;
 };
 typedef struct _sca_hash_table	sca_hash_table;
 
 #define sca_hash_table_index_for_key( ht1, str1 ) \
4cea9042
 	(get_hash1_raw((str1)->s, (str1)->len) & ((ht1)->size - 1 ))
d694ceba
 
 #define sca_hash_table_slot_for_index( ht1, idx1 ) \
 	&(ht1)->slots[ (idx1) ]
 
 #define sca_hash_table_lock_index( ht1, idx1 ) \
 	lock_get( &(ht1)->slots[ (idx1) ].lock )
 
 #define sca_hash_table_unlock_index( ht1, idx1 ) \
 	lock_release( &(ht1)->slots[ (idx1) ].lock )
 	
 
 /* hash table operations */
 int	sca_hash_table_create( sca_hash_table **, unsigned int );
 void	sca_hash_table_print( sca_hash_table * );
 void	sca_hash_table_free( sca_hash_table * );
 
a2f99b96
 void	sca_hash_entry_free( sca_hash_entry * );
 
d694ceba
 /* key-value operations */
 int	sca_hash_table_slot_kv_insert_unsafe( sca_hash_slot *, void *,
 				int (*)(str *, void *),
 				void (*)(void *), void (*)(void *));
 int	sca_hash_table_slot_kv_insert( sca_hash_slot *, void *,
 				int (*)(str *, void *),
 				void (*)(void *), void (*)(void *));
 int	sca_hash_table_index_kv_insert( sca_hash_table *, int, void *,
 				int (*)(str *, void *),
 				void (*)(void *), void (*)(void *));
 int	sca_hash_table_kv_insert( sca_hash_table *, str *, void *,
 				int (*)(str *, void *),
 				void (*)(void *), void (*)(void *));
 void	*sca_hash_table_slot_kv_find_unsafe( sca_hash_slot *, str * );
 void	*sca_hash_table_slot_kv_find( sca_hash_slot *, str * );
4369f775
 void	*sca_hash_table_index_kv_find_unsafe( sca_hash_table *, int, str * );
d694ceba
 void	*sca_hash_table_index_kv_find( sca_hash_table *, int, str * );
 void	*sca_hash_table_kv_find( sca_hash_table *, str * );
a2f99b96
 
 sca_hash_entry	*sca_hash_table_slot_kv_find_entry_unsafe( sca_hash_slot *,
 							    str * );
 sca_hash_entry *sca_hash_table_slot_unlink_entry_unsafe( sca_hash_slot *,
 						 	sca_hash_entry * );
 
d694ceba
 int	sca_hash_table_slot_kv_delete( sca_hash_slot *, str * );
 int	sca_hash_table_index_kv_delete( sca_hash_table *, int, str * );
 int	sca_hash_table_kv_delete( sca_hash_table *, str * );
 
 #endif /* SCA_HASH_H */