1 /**
2    r_assoc.h
3 
4 
5    Copyright (C) 2002-2003, Network Resonance, Inc.
6    Copyright (C) 2006, Network Resonance, Inc.
7    All Rights Reserved
8 
9    Redistribution and use in source and binary forms, with or without
10    modification, are permitted provided that the following conditions
11    are met:
12 
13    1. Redistributions of source code must retain the above copyright
14       notice, this list of conditions and the following disclaimer.
15    2. Redistributions in binary form must reproduce the above copyright
16       notice, this list of conditions and the following disclaimer in the
17       documentation and/or other materials provided with the distribution.
18    3. Neither the name of Network Resonance, Inc. nor the name of any
19       contributors to this software may be used to endorse or promote
20       products derived from this software without specific prior written
21       permission.
22 
23    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
24    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33    POSSIBILITY OF SUCH DAMAGE.
34 
35 
36  */
37 
38 /**
39    r_assoc.h
40 
41    Associative array code. This code has the advantage that different
42    elements can have different create and destroy operators. Unfortunately,
43    this can waste space.
44 
45 
46    Copyright (C) 1999-2000 RTFM, Inc.
47    All Rights Reserved
48 
49    This package is a SSLv3/TLS protocol analyzer written by Eric Rescorla
50    <ekr@rtfm.com> and licensed by RTFM, Inc.
51 
52    Redistribution and use in source and binary forms, with or without
53    modification, are permitted provided that the following conditions
54    are met:
55    1. Redistributions of source code must retain the above copyright
56       notice, this list of conditions and the following disclaimer.
57    2. Redistributions in binary form must reproduce the above copyright
58       notice, this list of conditions and the following disclaimer in the
59       documentation and/or other materials provided with the distribution.
60    3. All advertising materials mentioning features or use of this software
61       must display the following acknowledgement:
62 
63       This product includes software developed by Eric Rescorla for
64       RTFM, Inc.
65 
66    4. Neither the name of RTFM, Inc. nor the name of Eric Rescorla may be
67       used to endorse or promote products derived from this
68       software without specific prior written permission.
69 
70    THIS SOFTWARE IS PROVIDED BY ERIC RESCORLA AND RTFM, INC. ``AS IS'' AND
71    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
72    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
73    ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
74    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
75    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
76    OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
77    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
78    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
79    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY SUCH DAMAGE.
80 
81    $Id: r_assoc.h,v 1.3 2007/06/08 22:16:08 adamcain Exp $
82 
83 
84    ekr@rtfm.com  Sun Jan 17 17:57:18 1999
85  */
86 
87 
88 #ifndef _r_assoc_h
89 #define _r_assoc_h
90 
91 typedef struct r_assoc_ r_assoc;
92 
93 int r_assoc_create(r_assoc **assocp,
94                              int (*hash_func)(char *,int,int),
95                              int bits);
96 int r_assoc_insert(r_assoc *assoc,char *key,int len,
97   void *value,int (*copy)(void **knew,void *old),
98   int (*destroy)(void *ptr),int how);
99 #define R_ASSOC_REPLACE		  0x1
100 #define R_ASSOC_NEW		  0x2
101 
102 int r_assoc_fetch(r_assoc *assoc,char *key, int len, void **value);
103 int r_assoc_delete(r_assoc *assoc,char *key, int len);
104 
105 int r_assoc_copy(r_assoc **knew,r_assoc *old);
106 int r_assoc_destroy(r_assoc **assocp);
107 int r_assoc_simple_hash_compute(char *key, int len,int bits);
108 int r_assoc_crc32_hash_compute(char *key, int len,int bits);
109 
110 /*We need iterators, but I haven't written them yet*/
111 typedef struct r_assoc_iterator_ {
112      r_assoc *assoc;
113      int prev_chain;
114      struct r_assoc_el_ *prev;
115      int next_chain;
116      struct r_assoc_el_ *next;
117 } r_assoc_iterator;
118 
119 int r_assoc_init_iter(r_assoc *assoc,r_assoc_iterator *);
120 int r_assoc_iter(r_assoc_iterator *iter,void **key,int *keyl, void **val);
121 int r_assoc_iter_delete(r_assoc_iterator *);
122 
123 int r_assoc_num_elements(r_assoc *assoc,int *sizep);
124 
125 #endif
126 
127