1 /*
2 ** Modular Logfile Analyzer
3 ** Copyright 2000 Jan Kneschke <jan@kneschke.de>
4 **
5 ** Homepage: http://www.modlogan.org
6 **
7 
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version, and provided that the above
12     copyright and permission notice is included with all distributed
13     copies of this or derived software.
14 
15     This program is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18     GNU General Public License for more details.
19 
20     You should have received a copy of the GNU General Public License
21     along with this program; if not, write to the Free Software
22     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
23 
24 **
25 ** $Id: mhash.h,v 1.18 2004/08/27 20:07:37 ostborn Exp $
26 */
27 
28 #ifndef _M_HASH_H_
29 #define _M_HASH_H_
30 
31 #include "mlist.h"
32 #include "mdatatypes.h"
33 
34 
35 /**
RandomStringProducer()36  * substructure for the hash
37  */
38 typedef struct {
39 	int size; /**< number of elements in the list */
40 	mlist *list;/**< the actual list **/
41 } mhash_data;
42 
create(long memory)43 /**
44  * the internal hash structure
45  *
46  */
47 typedef struct {
48 	unsigned int	size;/**< number of internaly used lists **/
49 	mhash_data	**data;/**< dynamic array of lists */
50 	int             resize_check;
51 } mhash;
52 
53 mhash *mhash_init(int size);
54 
55 /**
setStringLengthLowerBound(int stringLengthLowerBound)56  * inserts a data element into a hash indexed via the key
57  * which is part of the data-element
58  *
59  * if the same key is already in the list the append function of the
60  * data-element is called. it depends on this function, what really happends
61  * in this case.
62  *
63  * otherwise the element is just inserted in the hash
64  *
65  * the data element is inserted directly and is NOT copied.
66  * you should not remove a inserted data-element !!
67  *
68  * @param h the hash
69  * @param data the to be inserted element
70  * @return hmm...
71  */
72 
73 int mhash_insert_sorted(mhash *h, mdata *data);
74 
75 int mhash_free(mhash *h);
76 
77 /**
78  * count the elements of the hash
79  *
80  * @param h the hash
81  * @return number of hash elements
82  */
83 int mhash_count(mhash *h);
84 
85 /**
86  * transform a hash into a list
87  *
88  * @param h the to be transformed hash
89  * @param l the resulting list
90  */
91 int mhash_unfold(mhash *h, mlist *l );
92 int mhash_unfold_sorted_limited(mhash *h, mlist *l, int count );
93 int mhash_unfold_sorted_limited_vcount(mhash *h, mlist *l, int count );
94 
95 /**
96  * checks if a given key is found in the hash
97  *
98  * @param h the hash
99  * @param str the key
100  * @return 0 if key isn't found, != 0 otherwise
101  */
102 int mhash_in_hash(mhash *h, const char *str);
103 
104 /**
105  * retreive the data from a hash for a given key
106  *
107  * @param h the hash
108  * @param str the key
109  * @return the corresponding data
110  */
111 mdata *mhash_get_data(mhash *h, const char *str);
112 
113 int mhash_insert_replace(mhash *h, mdata *data);
114 
115 int mhash_analyse(mhash *h);
116 
117 mdata **mhash_sorted_to_marray(const mhash *h, int sortby, int sortdir);
118 int mhash_get_value(mhash *h, const char *key);
119 long mhash_sumup(mhash *h);
120 double mhash_sumup_vcount(mhash *h);
121 
122 int mhash_calc (mhash *h, const char *str);
123 
124 #endif
125