1262395Sbapt/* Copyright (c) 2013, Vsevolod Stakhov
2262395Sbapt * All rights reserved.
3262395Sbapt *
4262395Sbapt * Redistribution and use in source and binary forms, with or without
5262395Sbapt * modification, are permitted provided that the following conditions are met:
6262395Sbapt *       * Redistributions of source code must retain the above copyright
7262395Sbapt *         notice, this list of conditions and the following disclaimer.
8262395Sbapt *       * Redistributions in binary form must reproduce the above copyright
9262395Sbapt *         notice, this list of conditions and the following disclaimer in the
10262395Sbapt *         documentation and/or other materials provided with the distribution.
11262395Sbapt *
12262395Sbapt * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
13262395Sbapt * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14262395Sbapt * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15262395Sbapt * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
16262395Sbapt * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17262395Sbapt * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18262395Sbapt * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
19262395Sbapt * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20262395Sbapt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21262395Sbapt * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22262395Sbapt */
23262395Sbapt
24262395Sbapt#ifndef __UCL_HASH_H
25262395Sbapt#define __UCL_HASH_H
26262395Sbapt
27262395Sbapt#include "ucl.h"
28262395Sbapt
29262395Sbapt/******************************************************************************/
30262395Sbapt
31279549Sbaptstruct ucl_hash_node_s;
32279549Sbapttypedef struct ucl_hash_node_s ucl_hash_node_t;
33262395Sbapt
34298166Sbapttypedef int (*ucl_hash_cmp_func) (const void* void_a, const void* void_b);
35298166Sbapttypedef void (*ucl_hash_free_func) (void *ptr);
36262395Sbapttypedef void* ucl_hash_iter_t;
37262395Sbapt
38262395Sbapt
39262395Sbapt/**
40262395Sbapt * Linear chained hashtable.
41262395Sbapt */
42279549Sbaptstruct ucl_hash_struct;
43279549Sbapttypedef struct ucl_hash_struct ucl_hash_t;
44262395Sbapt
45262395Sbapt
46262395Sbapt/**
47262395Sbapt * Initializes the hashtable.
48262395Sbapt */
49279549Sbaptucl_hash_t* ucl_hash_create (bool ignore_case);
50262395Sbapt
51262395Sbapt/**
52262395Sbapt * Deinitializes the hashtable.
53262395Sbapt */
54298166Sbaptvoid ucl_hash_destroy (ucl_hash_t* hashlin, ucl_hash_free_func func);
55262395Sbapt
56262395Sbapt/**
57262395Sbapt * Inserts an element in the the hashtable.
58262395Sbapt */
59264789Sbaptvoid ucl_hash_insert (ucl_hash_t* hashlin, const ucl_object_t *obj, const char *key,
60264789Sbapt		unsigned keylen);
61262395Sbapt
62262395Sbapt/**
63275223Sbapt * Replace element in the hash
64275223Sbapt */
65275223Sbaptvoid ucl_hash_replace (ucl_hash_t* hashlin, const ucl_object_t *old,
66275223Sbapt		const ucl_object_t *new);
67275223Sbapt
68275223Sbapt/**
69262395Sbapt * Delete an element from the the hashtable.
70262395Sbapt */
71264789Sbaptvoid ucl_hash_delete (ucl_hash_t* hashlin, const ucl_object_t *obj);
72262395Sbapt
73262395Sbapt/**
74262395Sbapt * Searches an element in the hashtable.
75262395Sbapt */
76264789Sbaptconst ucl_object_t* ucl_hash_search (ucl_hash_t* hashlin, const char *key,
77264789Sbapt		unsigned keylen);
78262395Sbapt
79262395Sbapt
80262395Sbapt/**
81262395Sbapt * Iterate over hash table
82262395Sbapt * @param hashlin hash
83262395Sbapt * @param iter iterator (must be NULL on first iteration)
84262395Sbapt * @return the next object
85262395Sbapt */
86264789Sbaptconst void* ucl_hash_iterate (ucl_hash_t *hashlin, ucl_hash_iter_t *iter);
87262395Sbapt
88262395Sbapt/**
89262395Sbapt * Check whether an iterator has next element
90262395Sbapt */
91279549Sbaptbool ucl_hash_iter_has_next (ucl_hash_t *hashlin, ucl_hash_iter_t iter);
92262395Sbapt
93262395Sbapt#endif
94