* index.c: Implementation of index.h.
*/
-#include <assert.h>
-#include <stdio.h>
-#include <stddef.h>
-
+#include "agedu.h"
#include "trie.h"
#include "index.h"
-#include "malloc.h"
+#include "alloc.h"
#define alignof(typ) ( offsetof(struct { char c; typ t; }, t) )
MAXDEPTH(NODE(ib->t, n->children[1])));
n->totalsize =
- (ELEMENT(ib->t, n->element)->blocks +
+ (ELEMENT(ib->t, n->element)->size +
(n->children[0] ? NODE(ib->t, n->children[0])->totalsize : 0) +
(n->children[1] ? NODE(ib->t, n->children[1])->totalsize : 0));
}
{
off_t node = OFFSET(ib->t, tf);
ib->currroot = avl_insert(ib, ib->currroot, node);
- ib->roots[ib->n++] = OFFSET(ib->t, ib->currroot);
+ ib->roots[ib->n++] = 0;
+}
+
+void indexbuild_tag(indexbuild *ib)
+{
+ if (ib->n > 0)
+ ib->roots[ib->n - 1] = OFFSET(ib->t, ib->currroot);
ib->firstmutable = ib->nodes + ib->nnodes;
}
void indexbuild_free(indexbuild *ib)
{
+ assert(ib->n == trie_count(ib->t));
sfree(ib);
}
if (n > count)
n = count;
+ assert(roots[n-1]);
node = NODE(t, roots[n-1]);
ret = 0;
} else {
if (left)
ret += left->totalsize;
- ret += tf->blocks;
+ ret += tf->size;
node = right;
}
}
roots = (const off_t *)((const char *)t + trie_get_index_offset(t));
count = trie_count(t);
+ assert(roots[count-1]);
node = NODE(t, roots[count-1]);
size = node->totalsize * f;
if (left && size < left->totalsize) {
node = left;
} else if (!right ||
- size < (left ? left->totalsize : 0) + tf->blocks) {
+ size < (left ? left->totalsize : 0) + tf->size) {
return tf->atime;
} else {
if (left)
size -= left->totalsize;
- size -= tf->blocks;
+ size -= tf->size;
node = right;
}
}