Annotation of libelwix/inc/elwix/aindex.h, revision 1.1.2.2
1.1.2.1 misho 1: /*************************************************************************
2: * (C) 2022 AITNET ltd - Sofia/Bulgaria - <misho@aitnet.org>
3: * by Michael Pounov <misho@elwix.org>
4: *
5: * $Author: misho $
1.1.2.2 ! misho 6: * $Id: aindex.h,v 1.1.2.1 2022/01/04 22:32:34 misho Exp $
1.1.2.1 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:
15: Copyright 2004 - 2022
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: /*
1.1.2.2 ! misho 64: * index_getList() - Get hash like list or first pointer
1.1.2.1 misho 65: */
1.1.2.2 ! misho 66: #define index_getList(x, k) (x)->i_hash[(k)]
! 67: #define index_Next(x) (x)->il_next
1.1.2.1 misho 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:
72:
73: /*
74: * index_Init() - Init index structure
75: *
76: * @idx = index, if it is NULL then it will be allocate
77: * return: NULL is error and !=NULL index ready for use
78: */
79: index_t *index_Init(index_t * __restrict idx);
80: /*
81: * index_FreeLists() - Free linked lists with data
82: *
83: * @idx = index
1.1.2.2 ! misho 84: * return: none
1.1.2.1 misho 85: */
86: void index_FreeLists(index_t *idx);
87: /*
88: * index_Destroy() - Destroy index
89: *
90: * @idx = index
1.1.2.2 ! misho 91: * return: none
1.1.2.1 misho 92: */
93: void index_Destroy(index_t **idx);
94:
95: /*
96: * index_add() - Adds item to index hash
97: *
98: * @idx = index
99: * @key = hash key
100: * @data = data
101: * @datlen = data length
102: * @hash = return calculated hash of data
103: * return: -1 error or 0 ok
104: */
105: int index_add(index_t *idx, unsigned short key, void *data, int datlen,
106: unsigned int *hash);
107: /*
108: * index_del() - Dels item from index hash
109: *
110: * @idx = index
111: * @key = hash key
112: * @data = data
113: * @datlen = data length
114: * return: -1 error, 0 nothing deleted and 1 item deleted
115: */
116: int index_del(index_t *idx, unsigned short key, void *data, int datlen);
117: /*
1.1.2.2 ! misho 118: * index_del2() - Dels item with index key and hash
! 119: *
! 120: * @idx = index
! 121: * @key = hash key
! 122: * @hash = calculated hash of item when its added to index
! 123: * return: -1 error, 0 nothing deleted and 1 item deleted
! 124: */
! 125: int index_del2(index_t *idx, unsigned short key, unsigned int hash);
! 126: /*
1.1.2.1 misho 127: * index_delList() - Delete list behind key
128: *
129: * @idx = index
130: * @key = Hash value
131: * return: -1 is error and 0 is ok
132: */
133: int index_delList(index_t *idx, unsigned short key);
134:
135: /*
136: * index_getArray() - Get list behind key into array
137: *
138: * @idx = index
139: * @key = Hash value
140: * return: NULL is error and !=NULL allocated array. It must be free after use
141: */
142: array_t *index_getArray(index_t *idx, unsigned short key);
143: /*
144: * index_get2() - Get item by key and hash
145: *
146: * @idx = index
147: * @key = hash key
148: * @hash = calculated hash of item when its added to index
149: * return: NULL error or not found and !=NULL returned item
150: */
151: index_list_t index_get2(index_t *idx, unsigned short key, unsigned int hash);
152: /*
153: * index_getVar() - Get item by key and hash as Var
154: *
155: * @idx = index
156: * @key = hash key
157: * @hash = calculated hash of item when its added to index
158: * return: NULL error or not found and !=NULL returned variable. Must be free after use!
159: */
160: ait_val_t *index_getVar(index_t *idx, u_short key, u_int hash);
161:
162:
1.1.2.2 ! misho 163: /*
! 164: * index_dump() - Debug routine about index hashes
! 165: *
! 166: * @idx = index
! 167: * return: none
! 168: */
! 169: void index_dump(index_t *idx);
! 170:
! 171:
1.1.2.1 misho 172: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>