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 2001-2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "gnu_msgfmt.h"
30 #include "gnu_prime.h"
36 * Calculates the hash value from the specified string.
37 * Actual hashid will be mod(hash value, PRIME_NUMBER).
39 * Ref: Compilers - Principles, Techniques, and Tools
40 * Aho, Sethi, and Ullman
43 hashpjw(const char *str
)
46 unsigned int h
= 0, g
;
48 for (p
= str
; *p
; p
++) {
61 find_prime_big(unsigned int n
)
64 unsigned int max_tbl_prime
, prd
;
65 max_tbl_prime
= prime
[MAX_PRIME_INDEX
] + 2;
68 for (t
= 1; t
<= MAX_PRIME_INDEX
; t
++) {
69 if (n
% prime
[t
] == 0) {
70 /* n is not a prime number */
74 if (t
<= MAX_PRIME_INDEX
) {
80 while ((prd
* prd
< n
) && (n
% prd
!= 0)) {
93 find_prime(unsigned int tbl_size
)
98 /* for compatibility with GNU msgfmt */
101 else if (tbl_size
== 2)
104 n
= 4 * tbl_size
/ 3;
106 /* make n an odd number */
110 if (prd
<= MAX_INDEX_INDEX
) {
111 /* first, search the table */
112 for (t
= index
[prd
] + 1; t
<= MAX_PRIME_INDEX
; t
++) {
119 t
= START_SEARCH_INDEX
;
121 while (prime
[t
] * prime
[t
] < n
) {
122 if (t
== MAX_PRIME_INDEX
) {
123 return (find_prime_big(n
));
127 for (d
= 1; d
<= t
; d
++) {
128 if (n
% prime
[d
] == 0) {
129 /* n is not a prime number */
134 /* n is a prime number */
143 get_hash_index(unsigned int *hash_tbl
, unsigned int hash_value
,
144 unsigned int hash_size
)
146 unsigned int idx
, inc
;
148 idx
= hash_value
% hash_size
;
149 inc
= 1 + (hash_value
% (hash_size
- 2));
154 idx
= (idx
+ inc
) % hash_size
;