summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Canciani <ranma42@gmail.com>2013-06-17 15:19:26 +0200
committerAndrea Canciani <ranma42@gmail.com>2013-06-17 15:19:26 +0200
commit37ed6c33ee0eab580e975e94fdd75d3125b4adf5 (patch)
tree0bb72865dcef77c7e689331e7b692b1655894c05
parent17fe53d1056c1651c8849ebd969c4e40b72a7418 (diff)
hashtable: foreach works on const hashtablesHEADmaster
The foreach function iterates over all of the elements and calls a function which is guaranteed to make no modification to the table, hence the whole loop never changes the hashtable. This makes it possible to nest two loops over the same hashtable without manual casting.
-rw-r--r--hashtable.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/hashtable.h b/hashtable.h
index 8a4bedb..4aca6b0 100644
--- a/hashtable.h
+++ b/hashtable.h
@@ -106,7 +106,7 @@ _simpledata_hashtable_size (size_t count, int shift)
visibility void prefix##_clear (prefix##_t *hashtable); \
visibility value_t prefix##_get (prefix##_t *hashtable, key_t key); \
visibility void \
- prefix##_foreach (prefix##_t *hashtable, \
+ prefix##_foreach (const prefix##_t *hashtable, \
void (*f) (const prefix##_t *hashtable, \
value_t data, void *arg), \
void *arg); \
@@ -322,7 +322,7 @@ _simpledata_hashtable_size (size_t count, int shift)
} \
\
visibility void \
- prefix##_foreach (prefix##_t *hashtable, \
+ prefix##_foreach (const prefix##_t *hashtable, \
void (*f) (const prefix##_t *hashtable, \
value_t data, void *arg), \
void *arg) \