diff --git a/src/Db.c b/src/Db.c index c50730a..5f43f1d 100644 --- a/src/Db.c +++ b/src/Db.c @@ -24,6 +24,7 @@ #include #include +#include #include @@ -46,6 +47,45 @@ struct DbRef char *file; }; +static ssize_t +DbComputeSize(HashMap *json) +{ + char *key; + JsonValue *val; + MemoryInfo *a; + size_t total; + + if (!json) + { + return -1; + } + + total = 0; + + a = MemoryInfoGet(json); + if (a) + { + total += MemoryInfoGetSize(a); + } + + while (HashMapIterate(json, &key, (void **) &val)) + { + a = MemoryInfoGet(key); + if (a) + { + total += MemoryInfoGetSize(a); + } + + a = MemoryInfoGet(val); + if (a) + { + total += MemoryInfoGetSize(a); + } + } + + return total; +} + Db * DbOpen(const char *dir, size_t cache) {