#define alignof(typ) ( offsetof(struct { char c; typ t; }, t) )
-#define min(x,y) ((x)<(y) ? (x):(y))
-#define max(x,y) ((x)>(y) ? (x):(y))
-
#define PADDING(x, mod) ( ((mod) - ((x) % (mod))) % (mod) )
struct avlnode {
off_t index_initial_size(off_t currentsize, int nodecount)
{
currentsize += PADDING(currentsize, alignof(off_t));
- currentsize += nodecount + sizeof(off_t);
+ currentsize += nodecount * sizeof(off_t);
currentsize += PADDING(currentsize, alignof(struct avlnode));
return currentsize;
ib->t = t;
ib->nodes = (struct avlnode *)((unsigned char *)ib->nodes + diff);
ib->roots = (off_t *)((unsigned char *)ib->roots + diff);
- ib->currroot = (struct avlnode *)((unsigned char *)ib->currroot + diff);
+ if (ib->currroot)
+ ib->currroot = (struct avlnode *)
+ ((unsigned char *)ib->currroot + diff);
ib->firstmutable = (struct avlnode *)((unsigned char *)ib->firstmutable + diff);
}
sfree(ib);
}
+int index_has_root(const void *t, int n)
+{
+ const off_t *roots;
+
+ roots = (const off_t *)((const char *)t + trie_get_index_offset(t));
+
+ if (n == 0)
+ return 1;
+ if (n < 0 || n >= trie_count(t) || !roots[n-1])
+ return 0;
+ return 1;
+}
+
unsigned long long index_query(const void *t, int n, unsigned long long at)
{
const off_t *roots;