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]
24 * Copyright 1990 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
32 #pragma ident "%Z%%M% %I% %E% SMI"
37 #define STRCMP(A, B) (cf(A, B) != 0)
38 #define FACTOR 035761254233 /* Magic multiplication factor */
39 #define TABLENGTH 64 /* must be multiple of 2 */
40 #define LOG2LEN 6 /* log2 of TABLENGTH */
43 NOTE: The following algorithm only works on machines where
44 the results of multiplying two integers is the least
45 significant part of the double word integer required to hold
46 the result. It is adapted from Knuth, Volume 3, section 6.4.
49 #define hash(str) (int)(((unsigned)(crunch(str) * FACTOR)) >> shift)
56 static struct node
**last
;
57 static struct node
*next
;
58 static struct node
**table
;
60 static unsigned int bitsper
; /* Bits per byte */
61 static unsigned int shift
;
63 static unsigned int crunch();
68 unsigned char c
= (unsigned char)~0; /* A byte full of 1's */
71 table
= (struct node
**)alloc(TABLENGTH
* sizeof(struct node
*));
73 for (j
=0; j
< TABLENGTH
; ++j
)
82 c
= (unsigned int)c
>> 1;
86 shift
= (bitsper
* sizeof(int)) - LOG2LEN
;
96 for (j
=0; j
< TABLENGTH
; ++j
)
131 while (p
!= 0 && (res
= STRCMP(str
, p
->item
.key
)))
137 if (p
!= 0 && res
== 0)
152 struct node
*p
= (struct node
*)alloc(sizeof(struct node
));
165 unsigned int sum
= 0;
168 for (s
= 0; *key
; s
++) /* Simply add up the bytes */