了解东京内阁中的tchdbfwmkeys方法(向前获取数据库中的匹配密钥)

时间:2019-06-27 08:49:20

标签: c tokyo-cabinet

我很难理解东京内阁的tchdbfwmkeys方法。

文档如下:

  

使用函数tchdbfwmkeys来获得哈希数据库对象中的前向匹配键。

TCLIST *tchdbfwmkeys(TCHDB *hdb, const void *pbuf, int psiz, int max);

    `hdb' specifies the hash database object. 

    `pbuf' specifies the pointer to the region of the prefix. 

    `psiz' specifies the size of the region of the prefix. 

    `max' specifies the maximum number of keys to be fetched. If it is negative, no limit is specified. 

    The return value is a list object of the corresponding keys. This function does never fail. It returns an empty list even if no key corresponds. 

    Because the object of the return value is created with the function `tclistnew', it should be deleted with the function `tclistdel' when it is no longer in use. Note that this function may be very slow because every key in the database is scanned. 

我对它的含义有一个模糊的理解:您传递一个键的前缀,它返回所有具有该前缀的键。例如,您传递前缀data_,并获得数据库中所有以data_开头的密钥。

我不确定这是否正确,即使我是,我也不了解pbufpsiz参数。你应该准确地传递给他们什么?

1 个答案:

答案 0 :(得分:0)

您的理解是正确的。

pbufpsiz:这是Toyko Cabinet中的常见模式。为了允许任意键,键(或键子字符串)不作为字符串传递,而是作为指向区域及其大小的指针。