From 6fb072f62c2f50118dd5cb377d10c76ece51e5fb Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Sun, 4 Oct 2020 14:36:07 +0200 Subject: Setze srcut-Marker... --- hashtab.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'hashtab.c') diff --git a/hashtab.c b/hashtab.c index 8a49baf..9f4e4a8 100644 --- a/hashtab.c +++ b/hashtab.c @@ -6,6 +6,7 @@ #include "util.h" +/* --8<-- hash_type */ typedef int T; struct hash_item { @@ -17,7 +18,9 @@ struct hash_item { struct hash_tab { struct hash_item *table[251]; // fit for your needs... }; +/* -->8-- */ +/* --8<-- hash_key */ static unsigned long hash_key(const unsigned char *str) { @@ -29,14 +32,18 @@ hash_key(const unsigned char *str) return hash; } +/* -->8-- */ +/* --8<-- hash_init */ void hash_init(struct hash_tab *ht) { for ( size_t i = 0; i != NELEM(ht->table); ++i ) ht->table[i] = NULL; } +/* -->8-- */ +/* --8<-- hash_add */ static struct hash_item * hash_add(struct hash_item *next, const char *key, T data) { @@ -59,7 +66,9 @@ hash_add(struct hash_item *next, const char *key, T data) return new_item; } +/* -->8-- */ +/* --8<-- hash_lookup */ T * hash_lookup(struct hash_tab *ht, const char *key, T data, int create) { @@ -82,7 +91,9 @@ hash_lookup(struct hash_tab *ht, const char *key, T data, int create) return item ? &item->data : NULL; } +/* -->8-- */ +/* --8<-- hash_delete */ bool hash_delete(struct hash_tab *ht, const char *key) { @@ -108,7 +119,9 @@ hash_delete(struct hash_tab *ht, const char *key) return false; } +/* -->8-- */ +/* --8<-- hash_apply */ void hash_apply(struct hash_tab *ht, void (*visit)(const char *key, T data, void *cl), void *cl) { @@ -118,7 +131,9 @@ hash_apply(struct hash_tab *ht, void (*visit)(const char *key, T data, void *cl) for ( item = ht->table[i]; item; item = item->next ) visit(item->key, item->data, cl); } +/* -->8-- */ +/* --8<-- hash_free */ void hash_free(struct hash_tab *ht) { @@ -133,6 +148,7 @@ hash_free(struct hash_tab *ht) ht->table[i] = NULL; } } +/* -->8-- */ static int getword(FILE *fp, char *buf, size_t size, int first(int), int rest(int)) -- cgit v1.3