如何列出雪松上的所有键(双数组trie)
How to list all keys on cedar (double-array trie)
我使用这个库来存储很多字符串。如何从这个库中获取所有密钥?
只有一种方法可以获得所有值,dump
函数行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中恢复长度为len的子字符串密钥。用户必须为密钥分配足够的内存(要存储终端字符,需要len+1个字节)。
但是如何知道len
和to
的参数呢?
找到它,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
}
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- 将数组的地址分配给变量并删除
- 从C++本机插件更新Vector3数组
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 数组索引的值没有增加
- 将对象数组的引用传递给函数
- 为char数组调整zlib-zpipe
- 2D数组来自文本输入,中间有空格
- std::向量与传递值的动态数组
- 在c++中用vector填充一个简单的动态数组
- 使用strcpy将char数组的元素复制到另一个数组
- 使用指针从C++中的数组中获取最大值
- C++使用整数的压缩数组初始化对象
- 告诉一个 const char 数组,除了编译时 C 样式的字符串外,它不以 '