/*++ /* NAME /* htable 3 /* SUMMARY /* hash table manager /* SYNOPSIS /* #include <htable.h> /* /* typedef struct { /* .in +4 /* char *key; /* void *value;
/* /* private fields... */ /* .in -4 /* } HTABLE_INFO; /* /* HTABLE *htable_create(size) /* int size; /* /* HTABLE_INFO *htable_enter(table, key, value) /* HTABLE *table; /* const char *key; /* void *value; /* /* char *htable_find(table, key) /* HTABLE *table; /* const char *key; /* /* HTABLE_INFO *htable_locate(table, key) /* HTABLE *table; /* const char *key; /* /* void htable_delete(table, key, free_fn) /* HTABLE *table; /* const char *key; /* void (*free_fn)(void *); /* /* void htable_free(table, free_fn) /* HTABLE *table; /* void (*free_fn)(void *); /* /* void htable_walk(table, action, ptr) /* HTABLE *table; /* void (*action)(HTABLE_INFO *, void *ptr); /* void *ptr; /* /* HTABLE_INFO **htable_list(table) /* HTABLE *table; /* /* HTABLE_INFO *htable_sequence(table, how) /* HTABLE *table; /* int how; /* DESCRIPTION /* This module maintains one or more hash tables. Each table entry /* consists of a unique string-valued lookup key and a generic /* character-pointer value. /* The tables are automatically resized when they fill up. When the /* values to be remembered are not character pointers, proper casts /* should be used or the code will not be portable. /* /* htable_create() creates a table of the specified size and returns a /* pointer to the result. The lookup keys are saved with mystrdup(). /* htable_enter() stores a (key, value) pair into the specified table /* and returns a pointer to the resulting entry. The code does not /* check if an entry with that key already exists: use htable_locate() /* for updating an existing entry. /* /* htable_find() returns the value that was stored under the given key, /* or a null pointer if it was not found. In order to distinguish /* a null value from a non-existent value, use htable_locate(). /* /* htable_locate() returns a pointer to the entry that was stored /* for the given key, or a null pointer if it was not found. /* /* htable_delete() removes one entry that was stored under the given key. /* If the free_fn argument is not a null pointer, the corresponding /* function is called with as argument the non-zero value stored under /* the key. /* /* htable_free() destroys a hash table, including contents. If the free_fn /* argument is not a null pointer, the corresponding function is called /* for each table entry, with as argument the non-zero value stored /* with the entry. /* /* htable_walk() invokes the action function for each table entry, with /* a pointer to the entry as its argument. The ptr argument is passed /* on to the action function. /* /* htable_list() returns a null-terminated list of pointers to /* all elements in the named table. The list should be passed to /* myfree(). /* /* htable_sequence() returns the first or next element depending /* on the value of the "how" argument. Specify HTABLE_SEQ_FIRST /* to start a new sequence, HTABLE_SEQ_NEXT to continue, and /* HTABLE_SEQ_STOP to terminate a sequence early. /* RESTRICTIONS /* A callback function should not modify the hash table that is /* specified to its caller. /* DIAGNOSTICS /* The following conditions are reported and cause the program to /* terminate immediately: memory allocation failure; an attempt /* to delete a non-existent entry. /* SEE ALSO /* mymalloc(3) memory management wrapper /* hash_fnv(3) Fowler/Noll/Vo hash function /* LICENSE /* .ad /* .fi /* The Secure Mailer license must be distributed with this software. /* AUTHOR(S) /* Wietse Venema /* IBM T.J. Watson Research /* P.O. Box 704 /* Yorktown Heights, NY 10598, USA /* /* Wietse Venema /* Google, Inc. /* 111 8th Avenue /* New York, NY 10011, USA
/*--*/
/* *Loadalargenumberofstringsanddeletetheminarandomorder.
*/
hash = htable_create(10); while (vstring_get(buf, VSTREAM_IN) != VSTREAM_EOF)
htable_enter(hash, vstring_str(buf), CAST_INT_TO_VOID_PTR(count++)); if (count != hash->used)
msg_panic("%ld entries stored, but %lu entries exist",
(long) count, (unsignedlong) hash->used); for (i = 0, op = HTABLE_SEQ_FIRST; htable_sequence(hash, op) != 0;
i++, op = HTABLE_SEQ_NEXT) /* void */ ; if (i != hash->used)
msg_panic("%ld entries found, but %lu entries exist",
(long) i, (unsignedlong) hash->used);
ht_info = htable_list(hash); for (i = 0; i < hash->used; i++) {
r = myrand() % hash->used;
info = ht_info[i];
ht_info[i] = ht_info[r];
ht_info[r] = info;
} for (ht = ht_info; *ht; ht++)
htable_delete(hash, ht[0]->key, (void (*) (void *)) 0); if (hash->used > 0)
msg_panic("%ld entries not deleted", (long) hash->used);
myfree((void *) ht_info);
htable_free(hash, (void (*) (void *)) 0);
vstring_free(buf); return (0);
}
#endif
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.17Bemerkung:
(vorverarbeitet am 2026-08-09)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.