1219820Sjeff/*
2219820Sjeff * Copyright (c) 2004-2006 Voltaire, Inc. All rights reserved.
3219820Sjeff * Copyright (c) 2002-2006 Mellanox Technologies LTD. All rights reserved.
4219820Sjeff * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5219820Sjeff *
6219820Sjeff * This software is available to you under a choice of one of two
7219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
8219820Sjeff * General Public License (GPL) Version 2, available from the file
9219820Sjeff * COPYING in the main directory of this source tree, or the
10219820Sjeff * OpenIB.org BSD license below:
11219820Sjeff *
12219820Sjeff *     Redistribution and use in source and binary forms, with or
13219820Sjeff *     without modification, are permitted provided that the following
14219820Sjeff *     conditions are met:
15219820Sjeff *
16219820Sjeff *      - Redistributions of source code must retain the above
17219820Sjeff *        copyright notice, this list of conditions and the following
18219820Sjeff *        disclaimer.
19219820Sjeff *
20219820Sjeff *      - Redistributions in binary form must reproduce the above
21219820Sjeff *        copyright notice, this list of conditions and the following
22219820Sjeff *        disclaimer in the documentation and/or other materials
23219820Sjeff *        provided with the distribution.
24219820Sjeff *
25219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32219820Sjeff * SOFTWARE.
33219820Sjeff *
34219820Sjeff */
35219820Sjeff
36219820Sjeff/* @(#) st.h 5.1 89/12/14 */
37219820Sjeff
38219820Sjeff#ifndef ST_INCLUDED
39219820Sjeff#define ST_INCLUDED
40219820Sjeff
41219820Sjeff#include <stdlib.h>
42219820Sjeff
43219820Sjeff#ifdef __cplusplus
44219820Sjeff#  define BEGIN_C_DECLS extern "C" {
45219820Sjeff#  define END_C_DECLS   }
46219820Sjeff#else				/* !__cplusplus */
47219820Sjeff#  define BEGIN_C_DECLS
48219820Sjeff#  define END_C_DECLS
49219820Sjeff#endif				/* __cplusplus */
50219820Sjeff
51219820SjeffBEGIN_C_DECLS
52219820Sjeff#define st_ptr_t unsigned long
53219820Sjefftypedef st_ptr_t st_data_t;
54219820Sjeff
55219820Sjeff#define ST_DATA_T_DEFINED
56219820Sjeff
57219820Sjefftypedef struct st_table st_table;
58219820Sjeff
59219820Sjeffstruct st_hash_type {
60219820Sjeff	int (*compare) (void *, void *);
61219820Sjeff	st_ptr_t(*hash) (void *);
62219820Sjeff};
63219820Sjeff
64219820Sjeffstruct st_table {
65219820Sjeff	struct st_hash_type *type;
66219820Sjeff	int num_bins;
67219820Sjeff	int num_entries;
68219820Sjeff	struct st_table_entry **bins;
69219820Sjeff};
70219820Sjeff
71219820Sjeff#define st_is_member(table,key) st_lookup(table,key,(st_data_t *)0)
72219820Sjeff
73219820Sjeffenum st_retval { ST_CONTINUE, ST_STOP, ST_DELETE };
74219820Sjeff
75219820Sjeffst_table *st_init_table(struct st_hash_type *);
76219820Sjeffst_table *st_init_table_with_size(struct st_hash_type *, size_t);
77219820Sjeffst_table *st_init_numtable(void);
78219820Sjeffst_table *st_init_numtable_with_size(size_t);
79219820Sjeffst_table *st_init_strtable(void);
80219820Sjeffst_table *st_init_strtable_with_size(size_t);
81219820Sjeffint st_delete(st_table *, st_data_t *, st_data_t *);
82219820Sjeffint st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t);
83219820Sjeffint st_insert(st_table *, st_data_t, st_data_t);
84219820Sjeffint st_lookup(st_table *, st_data_t, st_data_t *);
85219820Sjeffvoid st_foreach(st_table *,
86219820Sjeff		int (*)(st_data_t key, st_data_t val, st_data_t arg),
87219820Sjeff		st_data_t);
88219820Sjeffvoid st_add_direct(st_table *, st_data_t, st_data_t);
89219820Sjeffvoid st_free_table(st_table *);
90219820Sjeffvoid st_cleanup_safe(st_table *, st_data_t);
91219820Sjeffst_table *st_copy(st_table *);
92219820Sjeff
93219820Sjeff#define ST_NUMCMP	((int (*)()) 0)
94219820Sjeff#define ST_NUMHASH	((int (*)()) -2)
95219820Sjeff
96219820Sjeff#define st_numcmp	ST_NUMCMP
97219820Sjeff#define st_numhash	ST_NUMHASH
98219820Sjeff
99219820Sjeff/* int st_strhash(void); */
100219820Sjeff
101219820SjeffEND_C_DECLS
102219820Sjeff#endif				/* ST_INCLUDED */
103