fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef _ISNS_HTAB_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _ISNS_HTAB_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern "C" {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define HASH_RATIO (3)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_LOGSIZE (sizeof (uint32_t) * 8 - 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define HVAL_MASK (((uint32_t)1 << MAX_LOGSIZE) - 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define BAD_HVAL_MASK ((uint32_t)1 << MAX_LOGSIZE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define VALID_HVAL(H) ((H) & HVAL_MASK)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define BAD_HVAL(H) (((H) & BAD_HVAL_MASK) == BAD_HVAL_MASK)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FLAGS_CTRL_MASK (0x10000000)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FLAGS_CHUNK_MASK (0x00001111)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct htab_item {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t hval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct htab_item *next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} htab_item_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct htab_itemx {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t uid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t hval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int bf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct htab_itemx *l;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct htab_itemx *r;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct htab_itemx *n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} htab_itemx_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct htab {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct cache *c;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte htab_item_t **items;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t logsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t chunks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t mask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* AVL tree of the object UIDs */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte htab_itemx_t *avlt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* the biggest UID in the tree */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t buid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* fifo list of available UIDs */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte htab_itemx_t *list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte htab_itemx_t *tail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} htab_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define UID_FLAGS_SEQ (0x1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FOR_EACH_ITEM(HTAB, UID, STMT) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte UID = htab_get_next(HTAB, UID);\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (UID != 0) {\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMT\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte UID = htab_get_next(HTAB, UID);\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid htab_init(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortehtab_t *htab_create(int, uint16_t, uint16_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid htab_destroy(htab_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint32_t htab_compute_hval(const uchar_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint htab_add(htab_t *, void *, int, uint32_t *, int *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_obj_t *htab_remove(htab_t *, void *, uint32_t, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint htab_lookup(htab_t *, void *, uint32_t,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t *, int (*)(void *, void *), int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint32_t htab_get_next(htab_t *, uint32_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid htab_dump(htab_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _ISNS_HTAB_H */