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

How to list all keys on cedar (double-array trie)

本文关键字:数组 trie 何列出      更新时间:2023-10-16

我使用这个库来存储很多字符串。如何从这个库中获取所有密钥?

只有一种方法可以获得所有值,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个字节)。

但是如何知道lento的参数呢?

找到它,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
}