我正在使用this库存储大量字符串。如何从这个库中获取所有密钥?
获取所有值的唯一方法是dump
函数line 228
:
union { int i; value_type x; } b;
size_t num = 0, from = 0, p = 0;
char key[256] = {0};
for (b.i = begin (from, p); b.i != CEDAR_NO_PATH; b.i = next (from, p)) {
// b.x is the value
// which variable that contains `len` and `to`
// that I should pass to suffix function?
suffix(key, len, to);
}
在文档中声明要检索密钥,我们必须调用suffix
函数:
void suffix (char* key, const size_t len, size_t to)
在到达节点的trie中恢复length = len的子字符串键。必须为用户分配足够的内存(存储终端字符,需要len + 1个字节)。
但是如何知道len
和to
参数?
答案 0 :(得分:1)
找到它,p
是len
,from
是to
:
char key[256] = {0};
for (b.i = begin(from, p); b.i != CEDAR_NO_PATH; b.i = next(from, p)) {
// b.x is the value
suffix(key, p, from); // key now should hold the key
}