upscaledb offers a functionality called “Approximate Matching”. It allows you to look up values even if you do not know their exact key!
Imagine an embedded system with a sensor attached. At irregular intervals, the sensor returns a value which will then be stored in the database. Sometimes it returns a value every second, at other times it returns just one value per minute.
Your application stores these values and uses the current timestamp as a key.
Further imagine that the application now wants to check the sensor value at about 12:00 o’clock. Note the “about” - chances are low that there’s a key with an exact 12:00 o’clock timestamp. The application needs to retrieve a value which was stored at 12:00 o’clock or very close to it!
Approximate Matching gives that functionality. You can ask upscaledb to retrieve values which match a key exactly or which are lower or greater than this key, but still very close to it.
You can do this by specifying a combination of the following flags to
ups_find
or ups_cursor_find
:
Here’s a short example snippet to search for a key or the next greater key:
memset (&record, 0, sizeof (record));
memset (&key, 0, sizeof (key));
/* fill key */
if ((st = ups_db_find (db, NULL, &key, &record, UPS_FIND_GEQ_MATCH))
!= UPS_SUCCESS) {
// ...