![]() |
Storage Engine API
|
Compares two different IndexKeyEntry instances. More...
#include <index_entry_comparison.h>
Compares two different IndexKeyEntry instances.
The existence of compound indexes necessitates some complicated logic. This is meant to support the comparisons of IndexKeyEntries (that are stored in an index) with IndexSeekPoints (that were encoded with makeQueryObject) to support fine-grained control over whether the ranges of various keys comprising a compound index are inclusive or exclusive.
Public Member Functions | |
IndexEntryComparison (Ordering order) | |
bool | operator() (const IndexKeyEntry &lhs, const IndexKeyEntry &rhs) const |
int | compare (const IndexKeyEntry &lhs, const IndexKeyEntry &rhs) const |
Compares two IndexKeyEntries and returns -1 if lhs < rhs, 1 if lhs > rhs, and 0 otherwise. More... | |
Static Public Member Functions | |
static BSONObj | makeQueryObject (const BSONObj &keyPrefix, int prefixLen, bool prefixExclusive, const std::vector< const BSONElement *> &keySuffix, const std::vector< bool > &suffixInclusive, const int cursorDirection) |
Encodes the arguments into a query object suitable to pass in to compare(). More... | |
static BSONObj | makeQueryObject (const IndexSeekPoint &seekPoint, bool isForward) |
Private Attributes | |
const Ordering | _order |
|
inline |
int mongo::IndexEntryComparison::compare | ( | const IndexKeyEntry & | lhs, |
const IndexKeyEntry & | rhs | ||
) | const |
Compares two IndexKeyEntries and returns -1 if lhs < rhs, 1 if lhs > rhs, and 0 otherwise.
IndexKeyEntries are compared lexicographically field by field in the BSONObj, followed by the RecordId. Either lhs or rhs (but not both) can be a query object returned by makeQueryObject(). See makeQueryObject() for a description of how its arguments affect the outcome of the comparison.
|
static |
Encodes the arguments into a query object suitable to pass in to compare().
A query object is used for seeking an iterator to a position in a sorted index. The difference between a query object and the keys inserted into indexes is that query objects can be exclusive. This means that the first matching entry in the index is the first key in the index after the query. The meaning of "after" depends on cursorDirection.
The fields of the key are the combination of keyPrefix and keySuffix. The first prefixLen keys of keyPrefix are used, as well as the keys starting at the prefixLen index of keySuffix. The first prefixLen elements of keySuffix are ignored.
If a field is marked as exclusive, then comparisons stop after that field and return either higher or lower, even if that field compares equal. If prefixExclusive is true and prefixLen is greater than 0, then the last field in the prefix is marked as exclusive. It is illegal to specify prefixExclusive as true with a prefixLen of 0. Each bool in suffixInclusive, starting at index prefixLen, indicates whether the corresponding element in keySuffix is inclusive or exclusive.
Returned objects are for use in lookups only and should never be inserted into the database, as their format may change. The only reason this is the same type as the entries in an index is to support storage engines that require comparators that take arguments of the same type.
A cursurDirection of 1 indicates a forward cursor, and -1 indicates a reverse cursor. This effects the result when the exclusive field compares equal.
|
inlinestatic |
bool mongo::IndexEntryComparison::operator() | ( | const IndexKeyEntry & | lhs, |
const IndexKeyEntry & | rhs | ||
) | const |
|
private |