2 Copyright (c) 1995-1998 by Cisco systems, Inc.
4 Permission to use, copy, modify, and distribute this software for
5 any purpose and without fee is hereby granted, provided that this
6 copyright and permission notice appear on all copies of the
7 software and supporting documentation, the name of Cisco Systems,
8 Inc. not be used in advertising or publicity pertaining to
9 distribution of the program without specific prior permission, and
10 notice be given in supporting documentation that modification,
11 copying and distribution is by permission of Cisco Systems, Inc.
13 Cisco Systems, Inc. makes no representations about the suitability
14 of this software for any purpose. THIS SOFTWARE IS PROVIDED ``AS
15 IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
16 WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS FOR A PARTICULAR PURPOSE.
27 typedef struct entry ENTRY;
29 /* Calculate hash value from a string */
35 int len = strlen(name);
38 for (i = 0; i < len; i++) {
39 hashval += name[i] * (i + 1);
42 hashval = hashval > 0 ? hashval : -hashval;
46 /* Lookup a name in a hash table. Return its node if it exists, NULL
49 hash_lookup(hashtab, name)
54 int hashval = calculate_hash(name);
56 entry = hashtab[hashval % HASH_TAB_SIZE];
59 if (STREQ(name, entry->name))
60 /* Node exists in table. return it */
67 /* Add a node to a hash table. Return node if it exists, NULL
70 hash_add_entry(hashtab, newentry)
77 entry = hash_lookup(hashtab, newentry->name);
81 /* Node does not exist in table. Add it */
82 hashval = calculate_hash(newentry->name);
83 newentry->hash = hashtab[hashval % HASH_TAB_SIZE];
84 hashtab[hashval % HASH_TAB_SIZE] = newentry;
89 /* Return an array of pointers to all the entries in a hash table */
91 hash_get_entries(hashtab)
102 for (i = 0; i < HASH_TAB_SIZE; i++) {
113 cnt++; /* Add space for NULL entry at end */
115 p = entries = (void **) tac_malloc(cnt * sizeof(void *));
116 for (i = 0; i < HASH_TAB_SIZE; i++) {