summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cache.c7
-rw-r--r--src/cache_iterators.c16
-rw-r--r--src/hash.c17
3 files changed, 28 insertions, 12 deletions
diff --git a/src/cache.c b/src/cache.c
index 1e544a2..f95bef6 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -423,3 +423,10 @@ void cache_iterate(struct cache *c,
{
hashtable_iterate(c->h, data, iterate);
}
+
+void cache_iterate_limit(struct cache *c, void *data,
+ uint32_t from, uint32_t steps,
+ int (*iterate)(void *data1, void *data2))
+{
+ hashtable_iterate_limit(c->h, data, from, steps, iterate);
+}
diff --git a/src/cache_iterators.c b/src/cache_iterators.c
index 542ab91..b6688e9 100644
--- a/src/cache_iterators.c
+++ b/src/cache_iterators.c
@@ -33,12 +33,12 @@ struct __dump_container {
int type;
};
-static int do_dump(void *data1, struct hashtable_node *n)
+static int do_dump(void *data1, void *n)
{
char buf[1024];
int size;
struct __dump_container *container = data1;
- struct cache_object *obj = (struct cache_object *)n;
+ struct cache_object *obj = n;
char *data = obj->data;
unsigned i;
@@ -152,9 +152,9 @@ retry:
}
}
-static int do_commit_related(void *data, struct hashtable_node *n)
+static int do_commit_related(void *data, void *n)
{
- struct cache_object *obj = (struct cache_object *)n;
+ struct cache_object *obj = n;
if (ct_is_related(obj->ct))
__do_commit_step(data, obj);
@@ -163,9 +163,9 @@ static int do_commit_related(void *data, struct hashtable_node *n)
return 0;
}
-static int do_commit_master(void *data, struct hashtable_node *n)
+static int do_commit_master(void *data, void *n)
{
- struct cache_object *obj = (struct cache_object *)n;
+ struct cache_object *obj = n;
if (ct_is_related(obj->ct))
return 0;
@@ -207,10 +207,10 @@ void cache_commit(struct cache *c, struct nfct_handle *h)
res.tv_sec, res.tv_usec);
}
-static int do_flush(void *data, struct hashtable_node *n)
+static int do_flush(void *data, void *n)
{
struct cache *c = data;
- struct cache_object *obj = (struct cache_object *)n;
+ struct cache_object *obj = n;
cache_del(c, obj);
cache_object_free(obj);
diff --git a/src/hash.c b/src/hash.c
index 9c9ea5b..fe6a047 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -23,6 +23,7 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
struct hashtable *
hashtable_create(int hashsize, int limit,
@@ -111,21 +112,29 @@ int hashtable_flush(struct hashtable *table)
return 0;
}
-int hashtable_iterate(struct hashtable *table, void *data,
- int (*iterate)(void *data1, struct hashtable_node *n))
+int
+hashtable_iterate_limit(struct hashtable *table, void *data,
+ uint32_t from, uint32_t steps,
+ int (*iterate)(void *data1, void *n))
{
uint32_t i;
struct list_head *e, *tmp;
struct hashtable_node *n;
- for (i=0; i < table->hashsize; i++) {
+ for (i=from; i < table->hashsize && i < from+steps; i++) {
list_for_each_safe(e, tmp, &table->members[i]) {
n = list_entry(e, struct hashtable_node, head);
if (iterate(data, n) == -1)
return -1;
}
}
- return 0;
+ return i;
+}
+
+int hashtable_iterate(struct hashtable *table, void *data,
+ int (*iterate)(void *data1, void *n))
+{
+ return hashtable_iterate_limit(table, data, 0, UINT_MAX, iterate);
}
unsigned int hashtable_counter(const struct hashtable *table)