Product Documentation

c-treeDB API API for C

Previous Topic

Next Topic


Find a record located at about the given percentile value.


CTDBRET ctdbRecordAtPercentile(CTHANDLE Handle, NINT pecent);


ctdbRecordAtPercentile() read the record located at, approximately, the given percentile value.

Handle is a record handle and percent indicate the percentile value. The valid values for percent are from 0 to 100, indicating 0% to 100%. ctdbRecordAtPercentile() return CTDBRET_OK on success.

The record is located using the record handle current index. You may select a new current index by calling ctdbSetDefaultIndex() function. The table must have at least one index to be able to use this function.

The record returned is an approximation location indicated by the percentual value passed to ctdbRecordAtPercentile().

ctdbRecordAtPercentile(), which is based on c-tree low level function KeyAtPercentile(), and it is very efficient since it does not traverse all of the key values in order to determine the record located at the specified percentile. However, ctdbRecordAtPercentile() is only an approximation since it assumes that key values are uniformly distributed among all of the b-tree leaf nodes.

ctdbRecordAtPercentile() may be used to support scroll bar positioning, found in many GUI windowing environments, in the cases when the position must be maintained in key sequential order.



Symbolic Constant




ctdbRecordAtPercentile() returns CTDBRET_OK on success or c-treeDB API SDK error code on failure.

See c-treeDB API Errors and Return Values for a complete listing of valid c-treeDB API error codes and return values.


/* display the record at 50% of table */

if (ctdbRecordAtPercentile(hRecord, 50) == CTDBRET_OK)






printf("Faield with error %d\n", ctdbGetError(hRecord));


See also