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.
32 static int calculate_hash TAC_ARGS((const char *name));
34 /* Calculate hash value from a string */
40 int len = strlen(name);
43 for (i = 0; i < len; i++) {
44 hashval += name[i] * (i + 1);
47 hashval = hashval > 0 ? hashval : -hashval;
51 void *hash_lookup TAC_ARGS((void **hashtab, const char *name));
53 /* Lookup a name in a hash table. Return its node if it exists, NULL
56 hash_lookup(hashtab, name)
61 int hashval = calculate_hash(name);
63 entry = hashtab[hashval % HASH_TAB_SIZE];
66 if (STREQ(name, entry->name))
67 /* Node exists in table. return it */
74 void *hash_add_entry TAC_ARGS((void **hashtab, ENTRY *newentry));
76 /* Add a node to a hash table. Return node if it exists, NULL
79 hash_add_entry(hashtab, newentry)
86 entry = hash_lookup(hashtab, newentry->name);
90 /* Node does not exist in table. Add it */
91 hashval = calculate_hash(newentry->name);
92 newentry->hash = hashtab[hashval % HASH_TAB_SIZE];
93 hashtab[hashval % HASH_TAB_SIZE] = newentry;
98 void **hash_get_entries TAC_ARGS((void **hashtab));
100 /* Return an array of pointers to all the entries in a hash table */
102 hash_get_entries(hashtab)
113 for (i = 0; i < HASH_TAB_SIZE; i++) {
124 cnt++; /* Add space for NULL entry at end */
126 p = entries = (void **) tac_malloc(cnt * sizeof(void *));
127 for (i = 0; i < HASH_TAB_SIZE; i++) {