4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 #include <sys/types.h>
35 #define INJ_HASHSZ 211
38 struct inj_var
*v_next
;
44 inj_hash_create(inj_hash_t
*h
, ulong_t (*hfn
)(void *),
45 int (*cfn
)(void *, void *))
47 h
->h_hash
= inj_zalloc(sizeof (inj_var_t
*) * INJ_HASHSZ
);
48 h
->h_hashsz
= INJ_HASHSZ
;
56 inj_var_alloc(void *key
, uintmax_t value
, inj_var_t
*next
)
58 inj_var_t
*v
= inj_alloc(sizeof (inj_var_t
));
68 inj_var_free(inj_var_t
*v
, void (*freefn
)(inj_var_t
*, void *), void *arg
)
73 inj_free(v
, sizeof (inj_var_t
));
77 inj_hash_destroy(inj_hash_t
*h
, void (*freefn
)(inj_var_t
*, void *), void *arg
)
82 for (i
= 0; i
< h
->h_hashsz
; i
++) {
83 for (v
= h
->h_hash
[i
]; v
!= NULL
; v
= w
) {
85 inj_var_free(v
, freefn
, arg
);
89 inj_free(h
->h_hash
, sizeof (inj_var_t
*) * INJ_HASHSZ
);
93 inj_hash_insert(inj_hash_t
*h
, void *key
, uintmax_t value
)
95 size_t i
= h
->h_hashfn(key
) % h
->h_hashsz
;
98 for (v
= h
->h_hash
[i
]; v
!= NULL
; v
= v
->v_next
) {
99 if (h
->h_cmpfn(v
->v_key
, key
) == 0)
103 /* not found - make a new one */
104 v
= inj_var_alloc(key
, value
, h
->h_hash
[i
]);
112 inj_hash_lookup(inj_hash_t
*h
, void *key
)
114 size_t i
= h
->h_hashfn(key
) % h
->h_hashsz
;
117 for (v
= h
->h_hash
[i
]; v
!= NULL
; v
= v
->v_next
) {
118 if (h
->h_cmpfn(v
->v_key
, key
) == 0)
126 inj_hash_get_key(inj_var_t
*v
)
132 inj_hash_get_value(inj_var_t
*v
)
134 return (v
->v_uvalue
);
138 inj_hash_get_cookie(inj_var_t
*v
)
140 return ((void *)(uintptr_t)v
->v_uvalue
);