如何列出雪松上的所有键(双列trie)

时间:2015-02-17 01:14:06

标签: c++ c trie

我正在使用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个字节)。

但是如何知道lento参数?

1 个答案:

答案 0 :(得分:1)

找到它,plenfromto

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
}