1

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?

Sven
  • 496
  • 4
  • 9
Eldy
  • 1,027
  • 1
  • 13
  • 31

1 Answers1

0

You understanding is correct.

pbuf and psiz: This is a common pattern in 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.

Sven
  • 496
  • 4
  • 9