4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2000 by Sun Microsystems, Inc.
24 * All rights reserved.
26 #pragma ident "%Z%%M% %I% %E% SMI"
35 make_hash(int size
, Hash_type type
, ulong_t ident
)
39 if ((tbl
= malloc(sizeof (Hash_tbl
))) == 0)
42 if ((tbl
->t_entry
= calloc((unsigned)(sizeof (Hash_ent
*)), size
)) == 0)
54 get_hash(Hash_tbl
* tbl
, Addr key
, Half id
, int mode
)
60 if (tbl
->t_type
== HASH_STR
)
61 hashval
= elf_hash((const char *)key
);
65 bucket
= hashval
% tbl
->t_size
;
67 if (mode
& HASH_FND_ENT
) {
68 for (ent
= tbl
->t_entry
[bucket
]; ent
!= NULL
;
70 if (tbl
->t_type
== HASH_STR
) {
71 if ((strcmp((const char *)ent
->e_key
,
72 (const char *)key
) == 0) && ((id
== 0) ||
76 if (ent
->e_key
== key
)
81 if (!(mode
& HASH_ADD_ENT
))
85 * Key not found in this hash table ... insert new entry into bucket.
87 if ((ent
= calloc(sizeof (Hash_ent
), 1)) == 0)
91 ent
->e_hash
= hashval
;
94 * Hook into bucket chain
96 ent
->e_next
= tbl
->t_entry
[bucket
];
97 tbl
->t_entry
[bucket
] = ent
;