/* Copyright (c) 2013, Vsevolod Stakhov1* All rights reserved.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions are met:5* * Redistributions of source code must retain the above copyright6* notice, this list of conditions and the following disclaimer.7* * Redistributions in binary form must reproduce the above copyright8* notice, this list of conditions and the following disclaimer in the9* documentation and/or other materials provided with the distribution.10*11* THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY12* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED13* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE14* DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY15* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES16* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;17* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND18* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT19* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS20* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.21*/2223#ifndef __UCL_HASH_H24#define __UCL_HASH_H2526#include "ucl.h"2728/******************************************************************************/2930struct ucl_hash_node_s;31typedef struct ucl_hash_node_s ucl_hash_node_t;3233typedef int (*ucl_hash_cmp_func) (const void* void_a, const void* void_b);34typedef void (*ucl_hash_free_func) (ucl_object_t *ptr);35typedef void* ucl_hash_iter_t;363738/**39* Linear chained hashtable.40*/41struct ucl_hash_struct;42typedef struct ucl_hash_struct ucl_hash_t;434445/**46* Initializes the hashtable.47*/48ucl_hash_t* ucl_hash_create (bool ignore_case);4950/**51* Deinitializes the hashtable.52*/53void ucl_hash_destroy (ucl_hash_t* hashlin, ucl_hash_free_func func);5455/**56* Inserts an element in the the hashtable.57* @return true on success, false on failure (i.e. ENOMEM)58*/59bool ucl_hash_insert (ucl_hash_t* hashlin, const ucl_object_t *obj, const char *key,60unsigned keylen);6162/**63* Replace element in the hash64*/65void ucl_hash_replace (ucl_hash_t* hashlin, const ucl_object_t *old,66const ucl_object_t *new);6768/**69* Delete an element from the the hashtable.70*/71void ucl_hash_delete (ucl_hash_t* hashlin, const ucl_object_t *obj);7273/**74* Searches an element in the hashtable.75*/76const ucl_object_t* ucl_hash_search (ucl_hash_t* hashlin, const char *key,77unsigned keylen);787980/**81* Iterate over hash table82* @param hashlin hash83* @param iter iterator (must be NULL on first iteration)84* @param ep pointer record exception (such as ENOMEM), could be NULL85* @return the next object86*/87const void* ucl_hash_iterate2 (ucl_hash_t *hashlin, ucl_hash_iter_t *iter, int *ep);8889/**90* Helper macro to support older code91*/92#define ucl_hash_iterate(hl, ip) ucl_hash_iterate2((hl), (ip), NULL)9394/**95* Check whether an iterator has next element96*/97bool ucl_hash_iter_has_next (ucl_hash_t *hashlin, ucl_hash_iter_t iter);9899/**100* Reserves space in hash101* @return true on sucess, false on failure (e.g. ENOMEM)102* @param hashlin103*/104bool ucl_hash_reserve (ucl_hash_t *hashlin, size_t sz);105106void ucl_hash_sort (ucl_hash_t *hashlin, enum ucl_object_keys_sort_flags fl);107108#endif109110111