Deleted Added
sdiff udiff text old ( 173412 ) new ( 201227 )
full compact
1/* $FreeBSD: head/sbin/rcorder/hash.c 201227 2009-12-29 22:53:27Z ed $ */
2/* $NetBSD: hash.c,v 1.1.1.1 1999/11/19 04:30:56 mrg Exp $ */
3
4/*
5 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
6 * Copyright (c) 1988, 1989 by Adam de Boor
7 * Copyright (c) 1989 by Berkeley Softworks
8 * All rights reserved.
9 *

--- 88 unchanged lines hidden (view full) ---

98 *
99 * Side Effects:
100 * Memory is allocated for the initial bucket area.
101 *
102 *---------------------------------------------------------
103 */
104
105void
106Hash_InitTable(
107 register Hash_Table *t, /* Structure to use to hold table. */
108 int numBuckets) /* How many buckets to create for starters.
109 * This number is rounded up to a power of
110 * two. If <= 0, a reasonable default is
111 * chosen. The table will grow in size later
112 * as needed. */
113{
114 register int i;
115 register struct Hash_Entry **hp;
116

--- 28 unchanged lines hidden (view full) ---

145 *
146 * Side Effects:
147 * Lots of memory is freed up.
148 *
149 *---------------------------------------------------------
150 */
151
152void
153Hash_DeleteTable(Hash_Table *t)
154{
155 register struct Hash_Entry **hp, *h, *nexth = NULL;
156 register int i;
157
158 for (hp = t->bucketPtr, i = t->size; --i >= 0;) {
159 for (h = *hp++; h != NULL; h = nexth) {
160 nexth = h->next;
161 free((char *)h);

--- 22 unchanged lines hidden (view full) ---

184 *
185 * Side Effects:
186 * None.
187 *
188 *---------------------------------------------------------
189 */
190
191Hash_Entry *
192Hash_FindEntry(
193 Hash_Table *t, /* Hash table to search. */
194 char *key) /* A hash key. */
195{
196 register Hash_Entry *e;
197 register unsigned h;
198 register char *p;
199
200 for (h = 0, p = key; *p;)
201 h = (h << 5) - h + *p++;
202 p = key;

--- 18 unchanged lines hidden (view full) ---

221 * with the given key.
222 *
223 * Side Effects:
224 * Memory may be allocated, and the hash buckets may be modified.
225 *---------------------------------------------------------
226 */
227
228Hash_Entry *
229Hash_CreateEntry(
230 register Hash_Table *t, /* Hash table to search. */
231 char *key, /* A hash key. */
232 Boolean *newPtr) /* Filled in with TRUE if new entry created,
233 * FALSE otherwise. */
234{
235 register Hash_Entry *e;
236 register unsigned h;
237 register char *p;
238 int keylen;
239 struct Hash_Entry **hp;
240

--- 47 unchanged lines hidden (view full) ---

288 *
289 * Side Effects:
290 * Hash chain that entry lives in is modified and memory is freed.
291 *
292 *---------------------------------------------------------
293 */
294
295void
296Hash_DeleteEntry(Hash_Table *t, Hash_Entry *e)
297{
298 register Hash_Entry **hp, *p;
299
300 if (e == NULL)
301 return;
302 for (hp = &t->bucketPtr[e->namehash & t->mask];
303 (p = *hp) != NULL; hp = &p->next) {
304 if (p == e) {

--- 22 unchanged lines hidden (view full) ---

327 * The information in searchPtr is initialized so that successive
328 * calls to Hash_Next will return successive HashEntry's
329 * from the table.
330 *
331 *---------------------------------------------------------
332 */
333
334Hash_Entry *
335Hash_EnumFirst(
336 Hash_Table *t, /* Table to be searched. */
337 register Hash_Search *searchPtr)/* Area in which to keep state
338 * about search.*/
339{
340 searchPtr->tablePtr = t;
341 searchPtr->nextIndex = 0;
342 searchPtr->hashEntryPtr = NULL;
343 return Hash_EnumNext(searchPtr);
344}
345

--- 11 unchanged lines hidden (view full) ---

357 * Side Effects:
358 * The information in searchPtr is modified to advance to the
359 * next entry.
360 *
361 *---------------------------------------------------------
362 */
363
364Hash_Entry *
365Hash_EnumNext(
366 register Hash_Search *searchPtr) /* Area used to keep state about
367 search. */
368{
369 register Hash_Entry *e;
370 Hash_Table *t = searchPtr->tablePtr;
371
372 /*
373 * The hashEntryPtr field points to the most recently returned
374 * entry, or is nil if we are starting up. If not nil, we have

--- 28 unchanged lines hidden (view full) ---

403 * Side Effects:
404 * The entire hash table is moved, so any bucket numbers
405 * from the old table are invalid.
406 *
407 *---------------------------------------------------------
408 */
409
410static void
411RebuildTable(register Hash_Table *t)
412{
413 register Hash_Entry *e, *next = NULL, **hp, **xp;
414 register int i, mask;
415 register Hash_Entry **oldhp;
416 int oldsize;
417
418 oldhp = t->bucketPtr;
419 oldsize = i = t->size;

--- 16 unchanged lines hidden ---