Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.47 KB | None | 0 0
  1. /*
  2.  * Copyright (C) 2010 spy
  3.  *
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions are
  6.  * met:
  7.  *
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. The name of the author may not be used to endorse or promote products
  14.  *    derived from this software without specific prior written permission.
  15.  *
  16.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
  17.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19.  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  20.  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22.  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  24.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  25.  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  26.  * POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28. #ifndef __HASH_H__
  29. #define __HASH_H__
  30.  
  31. #include <sys/types.h>
  32.  
  33. typedef struct hash_node {
  34.     const char      *n_key;     /* hash key */
  35.     struct hash_node    *n_next;    /* next node */
  36.     struct hash_node    *n_prev;    /* previous node */
  37. } hash_node_t;
  38.  
  39. typedef struct hash_table {
  40.     const char      *t_name;    /* name */
  41.     size_t          t_off;      /* offset to node data */
  42.     size_t          t_size;     /* table size in elements */
  43.     size_t          t_nelem;    /* number of nodes */
  44.     boolean_t       t_nocase;   /* case-insensitive flag */
  45.     int         t_salt;     /* hash salt */
  46.     hash_node_t     *t_nodes;   /* node list */
  47.     hash_node_t     *t_table;   /* table array */
  48. } hash_table_t;
  49.  
  50. void hash_init(hash_table_t *tp, const char *name, size_t off, size_t size,
  51.            boolean_t nocase);
  52. void hash_fini(hash_table_t *tp);
  53. void hash_node_init(hash_node_t *np, const char *key);
  54. void hash_table_rehash(hash_table_t *tp, int salt);
  55. void hash_insert(hash_table_t *tp, hash_node_t *np);
  56. void hash_remove(hash_table_t *tp, hash_node_t *np);
  57. void *hash_find(hash_table_t *tp, const char *key);
  58.  
  59. #endif  /* __HASH_H__ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement