remove xvm/ipagent
[unleashed.git] / usr / src / cmd / tic / tic_hash.c
blobe9e74cc31a7602aedca937d36b2fac4eb3a74223
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 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
26 /* Copyright (c) 1988 AT&T */
27 /* All Rights Reserved */
30 * University Copyright- Copyright (c) 1982, 1986, 1988
31 * The Regents of the University of California
32 * All Rights Reserved
34 * University Acknowledgment- Portions of this document are derived from
35 * software developed by the University of California, Berkeley, and its
36 * contributors.
39 #pragma ident "%Z%%M% %I% %E% SMI"
42 *************************************************************************
43 * COPYRIGHT NOTICE *
44 *************************************************************************
45 * This software is copyright(C) 1982 by Pavel Curtis *
46 * *
47 * Permission is granted to reproduce and distribute *
48 * this file by any means so long as no fee is charged *
49 * above a nominal handling fee and so long as this *
50 * notice is always included in the copies. *
51 * *
52 * Other rights are reserved except as explicitly granted *
53 * by written permission of the author. *
54 * Pavel Curtis *
55 * Computer Science Dept. *
56 * 405 Upson Hall *
57 * Cornell University *
58 * Ithaca, NY 14853 *
59 * *
60 * Ph- (607) 256-4934 *
61 * *
62 * Pavel.Cornell@Udel-Relay(ARPAnet) *
63 * decvax!cornell!pavel(UUCPnet) *
64 *********************************************************************** */
67 * comp_hash.c --- Routines to deal with the hashtable of capability
68 * names.
70 * $Log: RCS/comp_hash.v $
71 * Revision 2.1 82/10/25 14:45:34 pavel
72 * Added Copyright Notice
74 * Revision 2.0 82/10/24 15:16:34 pavel
75 * Beta-one Test Release
77 * Revision 1.3 82/08/23 22:29:33 pavel
78 * The REAL Alpha-one Release Version
80 * Revision 1.2 82/08/19 19:09:46 pavel
81 * Alpha Test Release One
83 * Revision 1.1 82/08/12 18:36:23 pavel
84 * Initial revision
89 #include <strings.h>
90 #include "curses_inc.h"
91 #include "compiler.h"
93 static void make_nte(void);
94 static int hash_function(char *);
97 * make_hash_table()
99 * Takes the entries in cap_table[] and hashes them into cap_hash_table[]
100 * by name. There are Captabsize entries in cap_table[] and Hashtabsize
101 * slots in cap_hash_table[].
105 void
106 make_hash_table()
108 int i;
109 int hashvalue;
110 int collisions = 0;
112 make_nte();
113 for (i = 0; i < Captabsize; i++) {
114 hashvalue = hash_function(cap_table[i].nte_name);
115 DEBUG(9, "%d\n", hashvalue);
117 if (cap_hash_table[hashvalue] != NULL)
118 collisions++;
120 cap_table[i].nte_link = cap_hash_table[hashvalue];
121 cap_hash_table[hashvalue] = &cap_table[i];
124 DEBUG(3, "Hash table complete\n%d collisions ", collisions);
125 DEBUG(3, "out of %d entries\n", Captabsize);
126 return;
130 * Make the name_table_entry from the capnames.c set of tables.
132 static void
133 make_nte(void)
135 int i, n;
136 extern char *boolnames[], *numnames[], *strnames[];
138 n = 0;
140 for (i = 0; boolnames[i]; i++) {
141 cap_table[n].nte_link = NULL;
142 cap_table[n].nte_name = boolnames[i];
143 cap_table[n].nte_type = BOOLEAN;
144 cap_table[n].nte_index = i;
145 n++;
147 BoolCount = i;
149 for (i = 0; numnames[i]; i++) {
150 cap_table[n].nte_link = NULL;
151 cap_table[n].nte_name = numnames[i];
152 cap_table[n].nte_type = NUMBER;
153 cap_table[n].nte_index = i;
154 n++;
156 NumCount = i;
158 for (i = 0; strnames[i]; i++) {
159 cap_table[n].nte_link = NULL;
160 cap_table[n].nte_name = strnames[i];
161 cap_table[n].nte_type = STRING;
162 cap_table[n].nte_index = i;
163 n++;
165 StrCount = i;
167 Captabsize = n;
172 * int hash_function(string)
174 * Computes the hashing function on the given string.
176 * The current hash function is the sum of each consectutive pair
177 * of characters, taken as two-byte integers, mod Hashtabsize.
181 static int
182 hash_function(char *string)
184 long sum = 0;
186 while (*string) {
187 sum += *string + (*(string + 1) << 8);
188 string++;
191 return (sum % Hashtabsize);
197 * struct name_table_entry *
198 * find_entry(string)
200 * Finds the entry for the given string in the hash table if present.
201 * Returns a pointer to the entry in the table or 0 if not found.
205 struct name_table_entry *
206 find_entry(char *string)
208 int hashvalue;
209 struct name_table_entry *ptr;
211 hashvalue = hash_function(string);
213 ptr = cap_hash_table[hashvalue];
215 while (ptr != NULL &&
216 strcmp(ptr->nte_name, string) != 0)
217 ptr = ptr->nte_link;
219 return (ptr);