[Kamailio-Users] htable question

Daniel-Constantin Mierla miconda at gmail.com
Wed Mar 4 15:37:22 CET 2009


Hello Klaus,

On 03/04/2009 03:01 PM, Klaus Darilion wrote:
> Hi!
>
> Sorry for not knowing how hash table works, thus my questions may be a
> bit stupid:
>
> How many items can be stored in hashtable? Is it limited to "size"
> parameter, e.g. 10 means max. 1024 entries? Or is it as much as memory
> is available (what for is the size parameter in this case)?
>   
As much memory you have. The hash table is an array of lists. The array 
has the size (number of entries) 2 power "size".

For each item is computed an integer hash value and the item is stored 
in hash_array[hash_value%array_size].

The higher size decreases the chances of hash value collisions, so when 
searching, you jump directly to the list holding the item and that lists 
is not very big.

Most of modules that stores something in memory uses this approach 
(e.g., usrloc).
> How can I delete a key from htable? Example: I want to track concurrent
> calls (lets pretend there is no dialog module :-):
>
> # pseudo language
> if INVITE
>    $sht(a=>$ci) = $ts;
>    ...
>
> elseif BYE
>    $avp(s:duration) = $ts - $avp(s:duration);
>
>     # how to delete this key now from the htable?
>   

$sht(a=>$ci) = null;


> Is it possible to iterate over all entries in the htable?
>   
No, there are some operations that can work on many items based on 
regexp for deletion:

http://kamailio.org/docs/modules/1.5.x/htable.html#id2467797

Cheers,
Daniel

-- 
Daniel-Constantin Mierla
http://www.asipto.com





More information about the sr-users mailing list