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]
25 * Copyright (c) 1988-2000 by Sun Microsystems, Inc.
26 * All Rights Reserved.
29 #pragma ident "%Z%%M% %I% %E% SMI"
35 #include "db_headers.h"
43 #define LOWER(c) (isupper((c)) ? tolower((c)) : (c))
45 int strncasecmp(const char *s1
, const char *s2
, int n
);
48 #define LOWER(c) (isupper((c)) ? _tolower((c)) : (c))
52 /* Constructor: creates item using given character sequence and length */
53 item::item(char *str
, int n
)
56 if ((value
= new char[len
]) == NULL
)
57 FATAL("item::item: cannot allocate space", DB_MEMORY_LIMIT
);
59 (void) memcpy(value
, str
, len
);
63 /* Constructor: creates item by copying given item */
64 item::item(item
*model
)
67 if ((value
= new char[len
]) == NULL
)
68 FATAL(" item::item: cannot allocate space (2)",
71 (void) memcpy(value
, model
->value
, len
);
74 /* Prints contents of item to stdout */
79 for (i
= 0; i
< len
; i
++)
83 /* Equality test. 'casein' TRUE means case insensitive test. */
85 item::equal(item
* other
, bool_t casein
)
87 if (casein
) // case-insensitive
88 return ((len
== other
->len
) &&
89 (!strncasecmp(value
, other
->value
, len
)));
90 else // case sensitive
91 return ((len
== other
->len
) &&
92 (!memcmp(value
, other
->value
, len
)));
96 item::equal(char* other
, int olen
, bool_t casein
)
98 if (casein
) // case-insensitive
99 return ((len
== olen
) && (!strncasecmp(value
, other
, len
)));
100 else // case sensitive
101 return ((len
== olen
) && (!memcmp(value
, other
, len
)));
104 /* Return hash value. 'casein' TRUE means case insensitive test. */
106 item::get_hashval(bool_t casein
)
111 // we want to separate the cases so that we don't needlessly do
112 // an extra test for the case-sensitive branch in the for loop
113 if (casein
) { // case insensitive
114 for (i
= 0; i
< len
; i
++) {
115 hval
= ((hval
<<HASHSHIFT
)^hval
);
116 hval
+= (LOWER(value
[i
]) & HASHMASK
);
118 } else { // case sensitive
119 for (i
= 0; i
< len
; i
++) {
120 hval
= ((hval
<<HASHSHIFT
)^hval
);
121 hval
+= (value
[i
] & HASHMASK
);