简体   繁体   English

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

[英]Understanding the tchdbfwmkeys method (get forward matching keys in a database) in Tokyo Cabinet

I am having a hard time understanding the tchdbfwmkeys method in Tokyo Cabinet. 我很难理解Tokyo Cabinet中的tchdbfwmkeys方法。

The documentation is as follow: 文档如下:

The function tchdbfwmkeys is used in order to get forward matching keys in a hash database object. 使用函数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. 

I have a fuzzy understanding of what it means: you pass the prefix of a key and it returns all keys that have this prefix. 我对它的含义有一个模糊的理解:您传递一个键的前缀,它返回所有具有该前缀的键。 For example, you pass the prefix data_ and you get all the keys in the database that start with data_ . 例如,您传递前缀data_并获得数据库中所有以data_开头的键。

I am not really sure if this is right however, and even if it was, I don't understand the pbuf and psiz parameters. 我不确定这是否正确,即使是,我也不了解pbufpsiz参数。 What are you supposed to pass to them exactly? 你到底应该传递给他们什么?

You understanding is correct. 您的理解是正确的。

pbuf and psiz : This is a common pattern in Toyko Cabinet. pbufpsiz :这是Toyko Cabinet中的常见模式。 To allow arbitrary keys, a key (or key substring) is not passed as a string, but as a pointer to an area and its size. 为了允许任意键,键(或键子字符串)不作为字符串传递,而是作为指向区域及其大小的指针。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM