diff options
Diffstat (limited to 'src/mongo/bson/ordering.h')
-rw-r--r-- | src/mongo/bson/ordering.h | 92 |
1 files changed, 47 insertions, 45 deletions
diff --git a/src/mongo/bson/ordering.h b/src/mongo/bson/ordering.h index cb21dfb22d7..d6e26e0aadc 100644 --- a/src/mongo/bson/ordering.h +++ b/src/mongo/bson/ordering.h @@ -33,55 +33,57 @@ namespace mongo { - // todo: ideally move to db/ instead of bson/, but elim any dependencies first +// todo: ideally move to db/ instead of bson/, but elim any dependencies first - /** A precomputation of a BSON index or sort key pattern. That is something like: - { a : 1, b : -1 } - The constructor is private to make conversion more explicit so we notice where we call make(). - Over time we should push this up higher and higher. - */ - class Ordering { - unsigned bits; - Ordering(unsigned b) : bits(b) { } - public: - Ordering(const Ordering& r) : bits(r.bits) { } - void operator=(const Ordering& r) { - bits = r.bits; - } +/** A precomputation of a BSON index or sort key pattern. That is something like: + { a : 1, b : -1 } + The constructor is private to make conversion more explicit so we notice where we call make(). + Over time we should push this up higher and higher. +*/ +class Ordering { + unsigned bits; + Ordering(unsigned b) : bits(b) {} - /** so, for key pattern { a : 1, b : -1 } - get(0) == 1 - get(1) == -1 - */ - int get(int i) const { - return ((1 << i) & bits) ? -1 : 1; - } +public: + Ordering(const Ordering& r) : bits(r.bits) {} + void operator=(const Ordering& r) { + bits = r.bits; + } - // for woCompare... - unsigned descending(unsigned mask) const { return bits & mask; } + /** so, for key pattern { a : 1, b : -1 } + get(0) == 1 + get(1) == -1 + */ + int get(int i) const { + return ((1 << i) & bits) ? -1 : 1; + } - /*operator std::string() const { - StringBuilder buf; - for ( unsigned i=0; i<nkeys; i++) - buf.append( get(i) > 0 ? "+" : "-" ); - return buf.str(); - }*/ + // for woCompare... + unsigned descending(unsigned mask) const { + return bits & mask; + } - static Ordering make(const BSONObj& obj) { - unsigned b = 0; - BSONObjIterator k(obj); - unsigned n = 0; - while( 1 ) { - BSONElement e = k.next(); - if( e.eoo() ) - break; - uassert( 13103, "too many compound keys", n <= 31 ); - if( e.number() < 0 ) - b |= (1 << n); - n++; - } - return Ordering(b); - } - }; + /*operator std::string() const { + StringBuilder buf; + for ( unsigned i=0; i<nkeys; i++) + buf.append( get(i) > 0 ? "+" : "-" ); + return buf.str(); + }*/ + static Ordering make(const BSONObj& obj) { + unsigned b = 0; + BSONObjIterator k(obj); + unsigned n = 0; + while (1) { + BSONElement e = k.next(); + if (e.eoo()) + break; + uassert(13103, "too many compound keys", n <= 31); + if (e.number() < 0) + b |= (1 << n); + n++; + } + return Ordering(b); + } +}; } |