ngx_hash_t - basic usage

Maxim Dounin mdounin at mdounin.ru
Fri Sep 6 12:05:29 UTC 2013


Hello!

On Thu, Sep 05, 2013 at 12:00:39PM -0700, Michael Ellery wrote:

> devs,
> 
> I'm working on a module and I'd like to have a hash table to use across
> requests. I do, however, need to be able to both add and remove elements
> - does this implementation support removal?

It doesn't support removals (as well as additions after 
ngx_hash_init() is called).  It is meant to be created during 
configuration parsing, and used without any further modifications.

Note well that ngx_hash_init() might be costly as it tries to find 
an optimal hash table size.

> I'd appreciate any suggested examples to look at in the existing source
> to help get started with basic usage.

For very basic usage take a look at ngx_http_ssi_filter_module.c, 
it uses hash to speed up lookups of SSI command names in a static 
list.  Tha hash is created in ngx_http_ssi_init_main_conf() and 
then used by ngx_http_ssi_body_filter() to find a command.

More complete example can be found in ngx_http_map_module.c, as 
the map module is essentially an interface to create hashes using 
configuration directives.

-- 
Maxim Dounin
http://nginx.org/en/donation.html



More information about the nginx-devel mailing list