Annotation of libelwix/inc/elwix/aindex.h, revision 1.3
1.2 misho 1: /*************************************************************************
2: * (C) 2022 AITNET ltd - Sofia/Bulgaria - <misho@aitnet.org>
3: * by Michael Pounov <misho@elwix.org>
4: *
5: * $Author: misho $
1.3 ! misho 6: * $Id: aindex.h,v 1.2.38.1 2025/08/21 15:40:07 misho Exp $
1.2 misho 7: *
8: **************************************************************************
9: The ELWIX and AITNET software is distributed under the following
10: terms:
11:
12: All of the documentation and software included in the ELWIX and AITNET
13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
14:
1.3 ! misho 15: Copyright 2004 - 2024
1.2 misho 16: by Michael Pounov <misho@elwix.org>. All rights reserved.
17:
18: Redistribution and use in source and binary forms, with or without
19: modification, are permitted provided that the following conditions
20: are met:
21: 1. Redistributions of source code must retain the above copyright
22: notice, this list of conditions and the following disclaimer.
23: 2. Redistributions in binary form must reproduce the above copyright
24: notice, this list of conditions and the following disclaimer in the
25: documentation and/or other materials provided with the distribution.
26: 3. All advertising materials mentioning features or use of this software
27: must display the following acknowledgement:
28: This product includes software developed by Michael Pounov <misho@elwix.org>
29: ELWIX - Embedded LightWeight unIX and its contributors.
30: 4. Neither the name of AITNET nor the names of its contributors
31: may be used to endorse or promote products derived from this software
32: without specific prior written permission.
33:
34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37: ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44: SUCH DAMAGE.
45: */
46: #ifndef __AINDEX_H
47: #define __AINDEX_H
48:
49:
50: struct tagIndexList {
51: unsigned int il_hash;
52: unsigned long il_len;
53: void *il_ptr;
54: struct tagIndexList *il_next;
55: };
56: typedef struct tagIndexList *index_list_t;
57:
58: struct tagIndex {
59: index_list_t i_hash[65536];
60: };
61: typedef struct tagIndex index_t;
62:
63: /*
64: * index_getList() - Get hash like list or first pointer
65: */
66: #define index_getList(x, k) (x)->i_hash[(k)]
67: #define index_Next(x) (x)->il_next
68: #define index_Hash(x) (x)->il_hash
69: #define index_Len(x) (x)->il_len
70: #define index_Ptr(x) (x)->il_ptr
71:
1.3 ! misho 72: #ifdef __cplusplus
! 73: extern "C" {
! 74: #endif
1.2 misho 75:
76: /*
77: * index_Init() - Init index structure
78: *
79: * @idx = index, if it is NULL then it will be allocate
80: * return: NULL is error and !=NULL index ready for use
81: */
82: index_t *index_Init(index_t * __restrict idx);
83: /*
84: * index_FreeLists() - Free linked lists with data
85: *
86: * @idx = index
87: * return: none
88: */
89: void index_FreeLists(index_t *idx);
90: /*
91: * index_Destroy() - Destroy index
92: *
93: * @idx = index
94: * return: none
95: */
96: void index_Destroy(index_t **idx);
97:
98: /*
99: * index_add() - Adds item to index hash
100: *
101: * @idx = index
102: * @key = hash key
103: * @data = data
104: * @datlen = data length
105: * @hash = return calculated hash of data
106: * return: -1 error or 0 ok
107: */
108: int index_add(index_t *idx, unsigned short key, void *data, int datlen,
109: unsigned int *hash);
110: /*
111: * index_del() - Dels item from index hash
112: *
113: * @idx = index
114: * @key = hash key
115: * @data = data
116: * @datlen = data length
117: * return: -1 error, 0 nothing deleted and 1 item deleted
118: */
119: int index_del(index_t *idx, unsigned short key, void *data, int datlen);
120: /*
121: * index_del2() - Dels item with index key and hash
122: *
123: * @idx = index
124: * @key = hash key
125: * @hash = calculated hash of item when its added to index
126: * return: -1 error, 0 nothing deleted and 1 item deleted
127: */
128: int index_del2(index_t *idx, unsigned short key, unsigned int hash);
129: /*
130: * index_delList() - Delete list behind key
131: *
132: * @idx = index
133: * @key = Hash value
134: * return: -1 is error and 0 is ok
135: */
136: int index_delList(index_t *idx, unsigned short key);
137:
138: /*
139: * index_getArray() - Get list behind key into array
140: *
141: * @idx = index
142: * @key = Hash value
143: * return: NULL is error and !=NULL allocated array. It must be free after use
144: */
145: array_t *index_getArray(index_t *idx, unsigned short key);
146: /*
147: * index_get2() - Get item by key and hash
148: *
149: * @idx = index
150: * @key = hash key
151: * @hash = calculated hash of item when its added to index
152: * return: NULL error or not found and !=NULL returned item
153: */
154: index_list_t index_get2(index_t *idx, unsigned short key, unsigned int hash);
155: /*
156: * index_getVar() - Get item by key and hash as Var
157: *
158: * @idx = index
159: * @key = hash key
160: * @hash = calculated hash of item when its added to index
161: * return: NULL error or not found and !=NULL returned variable. Must be free after use!
162: */
163: ait_val_t *index_getVar(index_t *idx, u_short key, u_int hash);
164:
165:
166: /*
167: * index_dump() - Debug routine about index hashes
168: *
169: * @idx = index
170: * return: none
171: */
172: void index_dump(index_t *idx);
173:
1.3 ! misho 174: #ifdef __cplusplus
! 175: }
! 176: #endif
1.2 misho 177:
178: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>