1*7836SJohn.Forte@Sun.COM /* 2*7836SJohn.Forte@Sun.COM * CDDL HEADER START 3*7836SJohn.Forte@Sun.COM * 4*7836SJohn.Forte@Sun.COM * The contents of this file are subject to the terms of the 5*7836SJohn.Forte@Sun.COM * Common Development and Distribution License (the "License"). 6*7836SJohn.Forte@Sun.COM * You may not use this file except in compliance with the License. 7*7836SJohn.Forte@Sun.COM * 8*7836SJohn.Forte@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*7836SJohn.Forte@Sun.COM * or http://www.opensolaris.org/os/licensing. 10*7836SJohn.Forte@Sun.COM * See the License for the specific language governing permissions 11*7836SJohn.Forte@Sun.COM * and limitations under the License. 12*7836SJohn.Forte@Sun.COM * 13*7836SJohn.Forte@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each 14*7836SJohn.Forte@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*7836SJohn.Forte@Sun.COM * If applicable, add the following below this CDDL HEADER, with the 16*7836SJohn.Forte@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying 17*7836SJohn.Forte@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner] 18*7836SJohn.Forte@Sun.COM * 19*7836SJohn.Forte@Sun.COM * CDDL HEADER END 20*7836SJohn.Forte@Sun.COM */ 21*7836SJohn.Forte@Sun.COM 22*7836SJohn.Forte@Sun.COM /* 23*7836SJohn.Forte@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24*7836SJohn.Forte@Sun.COM * Use is subject to license terms. 25*7836SJohn.Forte@Sun.COM */ 26*7836SJohn.Forte@Sun.COM 27*7836SJohn.Forte@Sun.COM #ifndef _ISNS_HTAB_H 28*7836SJohn.Forte@Sun.COM #define _ISNS_HTAB_H 29*7836SJohn.Forte@Sun.COM 30*7836SJohn.Forte@Sun.COM #ifdef __cplusplus 31*7836SJohn.Forte@Sun.COM extern "C" { 32*7836SJohn.Forte@Sun.COM #endif 33*7836SJohn.Forte@Sun.COM 34*7836SJohn.Forte@Sun.COM #define HASH_RATIO (3) 35*7836SJohn.Forte@Sun.COM #define MAX_LOGSIZE (sizeof (uint32_t) * 8 - 1) 36*7836SJohn.Forte@Sun.COM #define HVAL_MASK (((uint32_t)1 << MAX_LOGSIZE) - 1) 37*7836SJohn.Forte@Sun.COM #define BAD_HVAL_MASK ((uint32_t)1 << MAX_LOGSIZE) 38*7836SJohn.Forte@Sun.COM #define VALID_HVAL(H) ((H) & HVAL_MASK) 39*7836SJohn.Forte@Sun.COM #define BAD_HVAL(H) (((H) & BAD_HVAL_MASK) == BAD_HVAL_MASK) 40*7836SJohn.Forte@Sun.COM 41*7836SJohn.Forte@Sun.COM #define FLAGS_CTRL_MASK (0x10000000) 42*7836SJohn.Forte@Sun.COM #define FLAGS_CHUNK_MASK (0x00001111) 43*7836SJohn.Forte@Sun.COM 44*7836SJohn.Forte@Sun.COM typedef struct htab_item { 45*7836SJohn.Forte@Sun.COM uint32_t hval; 46*7836SJohn.Forte@Sun.COM void *p; 47*7836SJohn.Forte@Sun.COM struct htab_item *next; 48*7836SJohn.Forte@Sun.COM } htab_item_t; 49*7836SJohn.Forte@Sun.COM 50*7836SJohn.Forte@Sun.COM typedef struct htab_itemx { 51*7836SJohn.Forte@Sun.COM uint32_t uid; 52*7836SJohn.Forte@Sun.COM uint32_t hval; 53*7836SJohn.Forte@Sun.COM uint32_t t; 54*7836SJohn.Forte@Sun.COM int bf; 55*7836SJohn.Forte@Sun.COM struct htab_itemx *l; 56*7836SJohn.Forte@Sun.COM struct htab_itemx *r; 57*7836SJohn.Forte@Sun.COM struct htab_itemx *n; 58*7836SJohn.Forte@Sun.COM } htab_itemx_t; 59*7836SJohn.Forte@Sun.COM 60*7836SJohn.Forte@Sun.COM typedef struct htab { 61*7836SJohn.Forte@Sun.COM int flags; 62*7836SJohn.Forte@Sun.COM struct cache *c; 63*7836SJohn.Forte@Sun.COM htab_item_t **items; 64*7836SJohn.Forte@Sun.COM uint16_t logsize; 65*7836SJohn.Forte@Sun.COM uint16_t chunks; 66*7836SJohn.Forte@Sun.COM uint32_t mask; 67*7836SJohn.Forte@Sun.COM uint32_t count; 68*7836SJohn.Forte@Sun.COM /* AVL tree of the object UIDs */ 69*7836SJohn.Forte@Sun.COM htab_itemx_t *avlt; 70*7836SJohn.Forte@Sun.COM /* the biggest UID in the tree */ 71*7836SJohn.Forte@Sun.COM uint32_t buid; 72*7836SJohn.Forte@Sun.COM /* fifo list of available UIDs */ 73*7836SJohn.Forte@Sun.COM htab_itemx_t *list; 74*7836SJohn.Forte@Sun.COM htab_itemx_t *tail; 75*7836SJohn.Forte@Sun.COM } htab_t; 76*7836SJohn.Forte@Sun.COM 77*7836SJohn.Forte@Sun.COM #define UID_FLAGS_SEQ (0x1) 78*7836SJohn.Forte@Sun.COM 79*7836SJohn.Forte@Sun.COM #define FOR_EACH_ITEM(HTAB, UID, STMT) \ 80*7836SJohn.Forte@Sun.COM {\ 81*7836SJohn.Forte@Sun.COM UID = htab_get_next(HTAB, UID);\ 82*7836SJohn.Forte@Sun.COM while (UID != 0) {\ 83*7836SJohn.Forte@Sun.COM STMT\ 84*7836SJohn.Forte@Sun.COM UID = htab_get_next(HTAB, UID);\ 85*7836SJohn.Forte@Sun.COM }\ 86*7836SJohn.Forte@Sun.COM } 87*7836SJohn.Forte@Sun.COM 88*7836SJohn.Forte@Sun.COM void htab_init(void); 89*7836SJohn.Forte@Sun.COM htab_t *htab_create(int, uint16_t, uint16_t); 90*7836SJohn.Forte@Sun.COM void htab_destroy(htab_t *); 91*7836SJohn.Forte@Sun.COM uint32_t htab_compute_hval(const uchar_t *); 92*7836SJohn.Forte@Sun.COM int htab_add(htab_t *, void *, int, uint32_t *, int *); 93*7836SJohn.Forte@Sun.COM isns_obj_t *htab_remove(htab_t *, void *, uint32_t, int); 94*7836SJohn.Forte@Sun.COM int htab_lookup(htab_t *, void *, uint32_t, 95*7836SJohn.Forte@Sun.COM uint32_t *, int (*)(void *, void *), int); 96*7836SJohn.Forte@Sun.COM uint32_t htab_get_next(htab_t *, uint32_t); 97*7836SJohn.Forte@Sun.COM #ifdef DEBUG 98*7836SJohn.Forte@Sun.COM void htab_dump(htab_t *); 99*7836SJohn.Forte@Sun.COM #endif 100*7836SJohn.Forte@Sun.COM 101*7836SJohn.Forte@Sun.COM #ifdef __cplusplus 102*7836SJohn.Forte@Sun.COM } 103*7836SJohn.Forte@Sun.COM #endif 104*7836SJohn.Forte@Sun.COM 105*7836SJohn.Forte@Sun.COM #endif /* _ISNS_HTAB_H */ 106