I am having a hard time understanding the tchdbfwmkeys
method in Tokyo Cabinet.
The documentation is as follow:
The function
tchdbfwmkeys
is used in order to get forward matching keys in a hash database object.
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_
.
I am not really sure if this is right however, and even if it was, I don't understand the pbuf
and psiz
parameters. What are you supposed to pass to them exactly?