1/*
2 * Copyright (c) 1984 through 2008, William LeFebvre
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 *     * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 *     * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 *
16 *     * Neither the name of William LeFebvre nor the names of other
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33/* hash.m4h */
34
35/* Interface definition for hash.c */
36
37/* The file hash.h is generated from hash.m4h via the preprocessor M4 */
38
39#ifndef _HASH_H
40#define _HASH_H
41
42#include <sys/types.h>
43
44typedef struct pidthr_t {
45    pid_t k_pid;
46    id_t k_thr;
47} pidthr_t;
48
49typedef struct llistitem {
50    void *datum;
51    struct llistitem *next;
52} llistitem;
53
54typedef struct llist {
55    llistitem *head;
56    unsigned int count;
57} llist;
58
59typedef struct bucket {
60    llist list;
61} bucket_t;
62
63typedef struct hash_table {
64    int num_buckets;
65    bucket_t *buckets;
66} hash_table;
67
68typedef struct hash_pos {
69    int num_buckets;
70    int curr;
71    bucket_t *hash_bucket;
72    llistitem *ll_item;
73    llistitem *ll_last;
74} hash_pos;
75
76hash_table *hash_create(int num);
77void hash_sizeinfo(unsigned int *sizes, int max, hash_table *ht);
78
79
80
81
82typedef struct hash_item_uint {
83    unsigned int key;
84    void *value;
85} hash_item_uint;
86
87void *hash_add_uint(hash_table *ht, unsigned int key, void *value);
88void *hash_replace_uint(hash_table *ht, unsigned int key, void *value);
89void *hash_lookup_uint(hash_table *ht, unsigned int key);
90void *hash_remove_uint(hash_table *ht, unsigned int key);
91hash_item_uint *hash_first_uint(hash_table *ht, hash_pos *pos);
92hash_item_uint *hash_next_uint(hash_pos *pos);
93void *hash_remove_pos_uint(hash_pos *pos);
94
95
96typedef struct hash_item_pid {
97    pid_t key;
98    void *value;
99} hash_item_pid;
100
101void *hash_add_pid(hash_table *ht, pid_t key, void *value);
102void *hash_replace_pid(hash_table *ht, pid_t key, void *value);
103void *hash_lookup_pid(hash_table *ht, pid_t key);
104void *hash_remove_pid(hash_table *ht, pid_t key);
105hash_item_pid *hash_first_pid(hash_table *ht, hash_pos *pos);
106hash_item_pid *hash_next_pid(hash_pos *pos);
107void *hash_remove_pos_pid(hash_pos *pos);
108
109
110typedef struct hash_item_string {
111    char * key;
112    void *value;
113} hash_item_string;
114
115void *hash_add_string(hash_table *ht, char * key, void *value);
116void *hash_replace_string(hash_table *ht, char * key, void *value);
117void *hash_lookup_string(hash_table *ht, char * key);
118void *hash_remove_string(hash_table *ht, char * key);
119hash_item_string *hash_first_string(hash_table *ht, hash_pos *pos);
120hash_item_string *hash_next_string(hash_pos *pos);
121void *hash_remove_pos_string(hash_pos *pos);
122
123
124typedef struct hash_item_pidthr {
125    pidthr_t key;
126    void *value;
127} hash_item_pidthr;
128
129void *hash_add_pidthr(hash_table *ht, pidthr_t key, void *value);
130void *hash_replace_pidthr(hash_table *ht, pidthr_t key, void *value);
131void *hash_lookup_pidthr(hash_table *ht, pidthr_t key);
132void *hash_remove_pidthr(hash_table *ht, pidthr_t key);
133hash_item_pidthr *hash_first_pidthr(hash_table *ht, hash_pos *pos);
134hash_item_pidthr *hash_next_pidthr(hash_pos *pos);
135void *hash_remove_pos_pidthr(hash_pos *pos);
136
137#if HAVE_LWPID_T
138
139typedef struct hash_item_lwpid {
140    lwpid_t key;
141    void *value;
142} hash_item_lwpid;
143
144void *hash_add_lwpid(hash_table *ht, lwpid_t key, void *value);
145void *hash_replace_lwpid(hash_table *ht, lwpid_t key, void *value);
146void *hash_lookup_lwpid(hash_table *ht, lwpid_t key);
147void *hash_remove_lwpid(hash_table *ht, lwpid_t key);
148hash_item_lwpid *hash_first_lwpid(hash_table *ht, hash_pos *pos);
149hash_item_lwpid *hash_next_lwpid(hash_pos *pos);
150void *hash_remove_pos_lwpid(hash_pos *pos);
151
152#endif
153
154
155#endif
156