File:  [ELWIX - Embedded LightWeight unIX -] / libelwix / inc / elwix / Attic / aindex.h
Revision 1.1.2.1: download - view: text, annotated - select for diffs - revision graph
Tue Jan 4 22:32:34 2022 UTC (2 years, 5 months ago) by misho
Branches: elwix5_0
adds new feature index structure for data

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>