Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

art插入的疑问 #7

Closed
skyelves opened this issue Feb 18, 2021 · 3 comments
Closed

art插入的疑问 #7

skyelves opened this issue Feb 18, 2021 · 3 comments

Comments

@skyelves
Copy link

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
Copy link
Owner

UncP commented Feb 18, 2021

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

@UncP UncP closed this as completed Feb 18, 2021
@skyelves
Copy link
Author

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

@UncP
Copy link
Owner

UncP commented Feb 18, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants