version 1.1, 2022/01/04 22:32:34
|
version 1.2, 2022/01/06 15:13:01
|
Line 0
|
Line 1
|
|
/************************************************************************* |
|
* (C) 2022 AITNET ltd - Sofia/Bulgaria - <misho@aitnet.org> |
|
* by Michael Pounov <misho@elwix.org> |
|
* |
|
* $Author$ |
|
* $Id$ |
|
* |
|
************************************************************************** |
|
The ELWIX and AITNET software is distributed under the following |
|
terms: |
|
|
|
All of the documentation and software included in the ELWIX and AITNET |
|
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
|
|
|
Copyright 2004 - 2022 |
|
by Michael Pounov <misho@elwix.org>. All rights reserved. |
|
|
|
Redistribution and use in source and binary forms, with or without |
|
modification, are permitted provided that the following conditions |
|
are met: |
|
1. Redistributions of source code must retain the above copyright |
|
notice, this list of conditions and the following disclaimer. |
|
2. Redistributions in binary form must reproduce the above copyright |
|
notice, this list of conditions and the following disclaimer in the |
|
documentation and/or other materials provided with the distribution. |
|
3. All advertising materials mentioning features or use of this software |
|
must display the following acknowledgement: |
|
This product includes software developed by Michael Pounov <misho@elwix.org> |
|
ELWIX - Embedded LightWeight unIX and its contributors. |
|
4. Neither the name of AITNET nor the names of its contributors |
|
may be used to endorse or promote products derived from this software |
|
without specific prior written permission. |
|
|
|
THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND |
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
SUCH DAMAGE. |
|
*/ |
|
#ifndef __AINDEX_H |
|
#define __AINDEX_H |
|
|
|
|
|
struct tagIndexList { |
|
unsigned int il_hash; |
|
unsigned long il_len; |
|
void *il_ptr; |
|
struct tagIndexList *il_next; |
|
}; |
|
typedef struct tagIndexList *index_list_t; |
|
|
|
struct tagIndex { |
|
index_list_t i_hash[65536]; |
|
}; |
|
typedef struct tagIndex index_t; |
|
|
|
/* |
|
* index_getList() - Get hash like list or first pointer |
|
*/ |
|
#define index_getList(x, k) (x)->i_hash[(k)] |
|
#define index_Next(x) (x)->il_next |
|
#define index_Hash(x) (x)->il_hash |
|
#define index_Len(x) (x)->il_len |
|
#define index_Ptr(x) (x)->il_ptr |
|
|
|
|
|
/* |
|
* index_Init() - Init index structure |
|
* |
|
* @idx = index, if it is NULL then it will be allocate |
|
* return: NULL is error and !=NULL index ready for use |
|
*/ |
|
index_t *index_Init(index_t * __restrict idx); |
|
/* |
|
* index_FreeLists() - Free linked lists with data |
|
* |
|
* @idx = index |
|
* return: none |
|
*/ |
|
void index_FreeLists(index_t *idx); |
|
/* |
|
* index_Destroy() - Destroy index |
|
* |
|
* @idx = index |
|
* return: none |
|
*/ |
|
void index_Destroy(index_t **idx); |
|
|
|
/* |
|
* index_add() - Adds item to index hash |
|
* |
|
* @idx = index |
|
* @key = hash key |
|
* @data = data |
|
* @datlen = data length |
|
* @hash = return calculated hash of data |
|
* return: -1 error or 0 ok |
|
*/ |
|
int index_add(index_t *idx, unsigned short key, void *data, int datlen, |
|
unsigned int *hash); |
|
/* |
|
* index_del() - Dels item from index hash |
|
* |
|
* @idx = index |
|
* @key = hash key |
|
* @data = data |
|
* @datlen = data length |
|
* return: -1 error, 0 nothing deleted and 1 item deleted |
|
*/ |
|
int index_del(index_t *idx, unsigned short key, void *data, int datlen); |
|
/* |
|
* index_del2() - Dels item with index key and hash |
|
* |
|
* @idx = index |
|
* @key = hash key |
|
* @hash = calculated hash of item when its added to index |
|
* return: -1 error, 0 nothing deleted and 1 item deleted |
|
*/ |
|
int index_del2(index_t *idx, unsigned short key, unsigned int hash); |
|
/* |
|
* index_delList() - Delete list behind key |
|
* |
|
* @idx = index |
|
* @key = Hash value |
|
* return: -1 is error and 0 is ok |
|
*/ |
|
int index_delList(index_t *idx, unsigned short key); |
|
|
|
/* |
|
* index_getArray() - Get list behind key into array |
|
* |
|
* @idx = index |
|
* @key = Hash value |
|
* return: NULL is error and !=NULL allocated array. It must be free after use |
|
*/ |
|
array_t *index_getArray(index_t *idx, unsigned short key); |
|
/* |
|
* index_get2() - Get item by key and hash |
|
* |
|
* @idx = index |
|
* @key = hash key |
|
* @hash = calculated hash of item when its added to index |
|
* return: NULL error or not found and !=NULL returned item |
|
*/ |
|
index_list_t index_get2(index_t *idx, unsigned short key, unsigned int hash); |
|
/* |
|
* index_getVar() - Get item by key and hash as Var |
|
* |
|
* @idx = index |
|
* @key = hash key |
|
* @hash = calculated hash of item when its added to index |
|
* return: NULL error or not found and !=NULL returned variable. Must be free after use! |
|
*/ |
|
ait_val_t *index_getVar(index_t *idx, u_short key, u_int hash); |
|
|
|
|
|
/* |
|
* index_dump() - Debug routine about index hashes |
|
* |
|
* @idx = index |
|
* return: none |
|
*/ |
|
void index_dump(index_t *idx); |
|
|
|
|
|
#endif |