dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / geniconvtbl / hash.h
blobe4cc2839138fe9c1d8e0c9ebbdbab66eb72a81e9
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #ifndef _ICONV_TM_HASH_H
28 #define _ICONV_TM_HASH_H
30 #pragma ident "%Z%%M% %I% %E% SMI"
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
39 static itm_size_t hash(const char *, itm_size_t, itm_size_t);
40 static itm_num_t hash_dense_encoding(const unsigned char *, itm_size_t,
41 const unsigned char *,
42 const unsigned char *);
45 static itm_size_t
46 hash(const char *ptr, itm_size_t size, itm_size_t hash_size)
48 itm_size_t value;
50 value = *(ptr++);
51 --size;
52 for (; 0 < size; --size) {
53 value *= 27239;
54 value += *(ptr++);
56 return (value % hash_size);
59 static itm_num_t
60 hash_dense_encoding(
61 const unsigned char *byte_seq,
62 itm_size_t length,
63 const unsigned char *byte_seq_min,
64 const unsigned char *byte_seq_max)
66 long i;
67 itm_num_t num;
69 num = (*byte_seq - *byte_seq_min);
70 byte_seq_min++;
71 byte_seq_max++;
72 for (i = 1, byte_seq++; i < length;
73 i++, byte_seq++, byte_seq_min++, byte_seq_max++) {
74 if ((*byte_seq < *byte_seq_min) ||
75 (*byte_seq_max < *byte_seq)) {
76 return (-1);
78 num *= (*byte_seq_max - *byte_seq_min + 1);
79 num += (*byte_seq - *byte_seq_min);
81 return (num);
84 #ifdef __cplusplus
86 #endif
88 #endif /* !_ICONV_TM_HASH_H */