UncP/aili

art插入的疑问

skyelves opened this issue · 3 comments

aili/test/one_test.c

Lines 124 to 127 in a2f3225

char *key = (*alloc)(16);
key[0] = 8;
*(uint64_t *)(key + 1)= rng_next(&r);
assert(adaptive_radix_tree_put(ta->tree.art, (const void *)(key + 1), 8) == 0);

这里插入为什么要malloc16个byte,同时空出第一个byte,是有什么concern吗

UncP commented

第一个 byte 用来存放 key 长度,第125行。

为什么需要把长度写两次,一个key[0],另一个adaptive_radix_tree_put的第三个参数?而且传入adaptive_radix_tree_put这个函数中时并没有用到key[0],但是函数里面却会用到key[0]这个值,有点不太理解这样做的目的

UncP commented

节省每个节点的大小,这样就不用在节点里添加 len[N] 这样的字段了