Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

remove BSONObjSetDefaultOrder and avoid inheriting from stl class

  • Loading branch information...
commit 41be5821f3a46bd817b0426dbe18cd9f85d5ad9b 1 parent 94a622f
@astaple astaple authored
View
5 bson/bsonmisc.h
@@ -33,15 +33,12 @@ namespace mongo {
bool operator()( const BSONObj &l, const BSONObj &r ) const {
return l.woCompare( r, _order ) < 0;
}
+ BSONObj order() const { return _order; }
private:
BSONObj _order;
};
typedef set<BSONObj,BSONObjCmp> BSONObjSet;
- class BSONObjSetDefaultOrder : public BSONObjSet {
- public:
- BSONObjSetDefaultOrder() : BSONObjSet( BSONObjCmp() ) {}
- };
enum FieldCompareResult {
LEFT_SUBFIELD = -2,
View
4 db/compact.h
@@ -33,10 +33,10 @@ namespace mongo {
bool multi; // multikey index
void addKeys(const IndexSpec& spec, const BSONObj& o, DiskLoc loc) {
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
spec.getKeys(o, keys);
int k = 0;
- for ( BSONObjSetDefaultOrder::iterator i=keys.begin(); i != keys.end(); i++ ) {
+ for ( BSONObjSet::iterator i=keys.begin(); i != keys.end(); i++ ) {
if( ++k == 2 ) {
multi = true;
}
View
10 db/index.cpp
@@ -144,13 +144,15 @@ namespace mongo {
}
}
- void IndexDetails::getKeysFromObject( const BSONObj& obj, BSONObjSetDefaultOrder& keys) const {
+ void IndexDetails::getKeysFromObject( const BSONObj& obj, BSONObjSet& keys) const {
getSpec().getKeys( obj, keys );
}
- void setDifference(BSONObjSetDefaultOrder &l, BSONObjSetDefaultOrder &r, vector<BSONObj*> &diff) {
- BSONObjSetDefaultOrder::iterator i = l.begin();
- BSONObjSetDefaultOrder::iterator j = r.begin();
+ void setDifference(BSONObjSet &l, BSONObjSet &r, vector<BSONObj*> &diff) {
+ // l and r must use the same ordering spec.
+ verify( 14819, l.key_comp().order() == r.key_comp().order() );
+ BSONObjSet::iterator i = l.begin();
+ BSONObjSet::iterator j = r.begin();
while ( 1 ) {
if ( i == l.end() )
break;
View
6 db/index.h
@@ -83,7 +83,7 @@ namespace mongo {
only when it's a "multikey" array.
keys will be left empty if key not found in the object.
*/
- void getKeysFromObject( const BSONObj& obj, BSONObjSetDefaultOrder& keys) const;
+ void getKeysFromObject( const BSONObj& obj, BSONObjSet& keys) const;
/* get the key pattern for this object.
e.g., { lastname:1, firstname:1 }
@@ -190,8 +190,8 @@ namespace mongo {
};
struct IndexChanges { /*on an update*/
- BSONObjSetDefaultOrder oldkeys;
- BSONObjSetDefaultOrder newkeys;
+ BSONObjSet oldkeys;
+ BSONObjSet newkeys;
vector<BSONObj*> removed; // these keys were removed as part of the change
vector<BSONObj*> added; // these keys were added as part of the change
View
12 db/pdfile.cpp
@@ -874,10 +874,10 @@ namespace mongo {
/* unindex all keys in index for this record. */
static void _unindexRecord(IndexDetails& id, BSONObj& obj, const DiskLoc& dl, bool logMissing = true) {
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id.getKeysFromObject(obj, keys);
IndexInterface& ii = id.idxInterface();
- for ( BSONObjSetDefaultOrder::iterator i=keys.begin(); i != keys.end(); i++ ) {
+ for ( BSONObjSet::iterator i=keys.begin(); i != keys.end(); i++ ) {
BSONObj j = *i;
if ( otherTraceLevel >= 5 ) {
out() << "_unindexRecord() " << obj.toString() << endl;
@@ -1112,7 +1112,7 @@ namespace mongo {
/* add keys to index idxNo for a new record */
static inline void _indexRecord(NamespaceDetails *d, int idxNo, BSONObj& obj, DiskLoc recordLoc, bool dupsAllowed) {
IndexDetails& idx = d->idx(idxNo);
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
idx.getKeysFromObject(obj, keys);
if( keys.empty() )
return;
@@ -1120,7 +1120,7 @@ namespace mongo {
IndexInterface& ii = idx.idxInterface();
Ordering ordering = Ordering::make(order);
int n = 0;
- for ( BSONObjSetDefaultOrder::iterator i=keys.begin(); i != keys.end(); i++ ) {
+ for ( BSONObjSet::iterator i=keys.begin(); i != keys.end(); i++ ) {
if( ++n == 2 ) {
d->setIndexIsMultikey(idxNo);
}
@@ -1541,11 +1541,11 @@ namespace mongo {
for ( int idxNo = 0; idxNo < d->nIndexes; idxNo++ ) {
if( d->idx(idxNo).unique() ) {
IndexDetails& idx = d->idx(idxNo);
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
idx.getKeysFromObject(obj, keys);
BSONObj order = idx.keyPattern();
IndexInterface& ii = idx.idxInterface();
- for ( BSONObjSetDefaultOrder::iterator i=keys.begin(); i != keys.end(); i++ ) {
+ for ( BSONObjSet::iterator i=keys.begin(); i != keys.end(); i++ ) {
// WARNING: findSingle may not be compound index safe. this may need to change. see notes in
// findSingle code.
uassert( 12582, "duplicate key insert for unique index of capped collection",
View
4 db/queryutil.cpp
@@ -1179,9 +1179,9 @@ namespace mongo {
// fields individually instead of constructing several bson objects using
// multikey arrays.) But getKeys() canonically defines the key set for a
// given object and for now we are using it as is.
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
_indexSpec.getKeys( obj, keys );
- for( BSONObjSetDefaultOrder::const_iterator i = keys.begin(); i != keys.end(); ++i ) {
+ for( BSONObjSet::const_iterator i = keys.begin(); i != keys.end(); ++i ) {
if ( matchesKey( *i ) ) {
return true;
}
View
62 dbtests/namespacetests.cpp
@@ -90,8 +90,8 @@ namespace NamespaceTests {
b.append( "c", 4 );
return b.obj();
}
- static void checkSize( int expected, const BSONObjSetDefaultOrder &objs ) {
- ASSERT_EQUALS( BSONObjSetDefaultOrder::size_type( expected ), objs.size() );
+ static void checkSize( int expected, const BSONObjSet &objs ) {
+ ASSERT_EQUALS( BSONObjSet::size_type( expected ), objs.size() );
}
static void assertEquals( const BSONObj &a, const BSONObj &b ) {
if ( a.woCompare( b ) != 0 ) {
@@ -128,7 +128,7 @@ namespace NamespaceTests {
b.append( "b", 4 );
b.append( "a", 5 );
e.append( "", 5 );
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id().getKeysFromObject( b.done(), keys );
checkSize( 1, keys );
assertEquals( e.obj(), *keys.begin() );
@@ -144,7 +144,7 @@ namespace NamespaceTests {
a.append( "a", b.done() );
a.append( "c", "foo" );
e.append( "", 4 );
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id().getKeysFromObject( a.done(), keys );
checkSize( 1, keys );
ASSERT_EQUALS( e.obj(), *keys.begin() );
@@ -162,11 +162,11 @@ namespace NamespaceTests {
BSONObjBuilder b;
b.append( "a", shortArray()) ;
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id().getKeysFromObject( b.done(), keys );
checkSize( 3, keys );
int j = 1;
- for ( BSONObjSetDefaultOrder::iterator i = keys.begin(); i != keys.end(); ++i, ++j ) {
+ for ( BSONObjSet::iterator i = keys.begin(); i != keys.end(); ++i, ++j ) {
BSONObjBuilder b;
b.append( "", j );
assertEquals( b.obj(), *i );
@@ -182,11 +182,11 @@ namespace NamespaceTests {
b.append( "a", shortArray() );
b.append( "b", 2 );
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id().getKeysFromObject( b.done(), keys );
checkSize( 3, keys );
int j = 1;
- for ( BSONObjSetDefaultOrder::iterator i = keys.begin(); i != keys.end(); ++i, ++j ) {
+ for ( BSONObjSet::iterator i = keys.begin(); i != keys.end(); ++i, ++j ) {
BSONObjBuilder b;
b.append( "", j );
b.append( "", 2 );
@@ -207,11 +207,11 @@ namespace NamespaceTests {
b.append( "first", 5 );
b.append( "a", shortArray()) ;
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id().getKeysFromObject( b.done(), keys );
checkSize( 3, keys );
int j = 1;
- for ( BSONObjSetDefaultOrder::iterator i = keys.begin(); i != keys.end(); ++i, ++j ) {
+ for ( BSONObjSet::iterator i = keys.begin(); i != keys.end(); ++i, ++j ) {
BSONObjBuilder b;
b.append( "", 5 );
b.append( "", j );
@@ -236,11 +236,11 @@ namespace NamespaceTests {
BSONObjBuilder a;
a.append( "a", b.done() );
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id().getKeysFromObject( a.done(), keys );
checkSize( 3, keys );
int j = 1;
- for ( BSONObjSetDefaultOrder::iterator i = keys.begin(); i != keys.end(); ++i, ++j ) {
+ for ( BSONObjSet::iterator i = keys.begin(); i != keys.end(); ++i, ++j ) {
BSONObjBuilder b;
b.append( "", j );
assertEquals( b.obj(), *i );
@@ -260,7 +260,7 @@ namespace NamespaceTests {
b.append( "a", shortArray() );
b.append( "b", shortArray() );
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
ASSERT_EXCEPTION( id().getKeysFromObject( b.done(), keys ),
UserException );
}
@@ -280,11 +280,11 @@ namespace NamespaceTests {
BSONObjBuilder b;
b.append( "a", elts );
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id().getKeysFromObject( b.done(), keys );
checkSize( 3, keys );
int j = 1;
- for ( BSONObjSetDefaultOrder::iterator i = keys.begin(); i != keys.end(); ++i, ++j ) {
+ for ( BSONObjSet::iterator i = keys.begin(); i != keys.end(); ++i, ++j ) {
BSONObjBuilder b;
b.append( "", j );
assertEquals( b.obj(), *i );
@@ -307,11 +307,11 @@ namespace NamespaceTests {
b.append( "a", elts );
b.append( "d", 99 );
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id().getKeysFromObject( b.done(), keys );
checkSize( 3, keys );
int j = 1;
- for ( BSONObjSetDefaultOrder::iterator i = keys.begin(); i != keys.end(); ++i, ++j ) {
+ for ( BSONObjSet::iterator i = keys.begin(); i != keys.end(); ++i, ++j ) {
BSONObjBuilder c;
c.append( "", j );
c.append( "", 99 );
@@ -340,10 +340,10 @@ namespace NamespaceTests {
BSONObjBuilder b;
b.append( "a", elts );
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id().getKeysFromObject( b.done(), keys );
checkSize( 4, keys );
- BSONObjSetDefaultOrder::iterator i = keys.begin();
+ BSONObjSet::iterator i = keys.begin();
assertEquals( nullObj(), *i++ );
for ( int j = 1; j < 4; ++i, ++j ) {
BSONObjBuilder b;
@@ -369,7 +369,7 @@ namespace NamespaceTests {
BSONObjBuilder b;
b.append( "a", elts );
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id().getKeysFromObject( b.done(), keys );
checkSize( 1, keys );
assertEquals( nullObj(), *keys.begin() );
@@ -384,7 +384,7 @@ namespace NamespaceTests {
public:
void run() {
create();
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id().getKeysFromObject( BSON( "b" << 1 ), keys );
checkSize( 1, keys );
assertEquals( nullObj(), *keys.begin() );
@@ -399,7 +399,7 @@ namespace NamespaceTests {
public:
void run() {
create();
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id().getKeysFromObject( fromjson( "{a:[1,2]}" ), keys );
checkSize( 1, keys );
assertEquals( nullObj(), *keys.begin() );
@@ -416,14 +416,14 @@ namespace NamespaceTests {
create();
{
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id().getKeysFromObject( fromjson( "{x:'a',y:'b'}" ) , keys );
checkSize( 1 , keys );
assertEquals( BSON( "" << "a" << "" << "b" ) , *keys.begin() );
}
{
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id().getKeysFromObject( fromjson( "{x:'a'}" ) , keys );
checkSize( 1 , keys );
BSONObjBuilder b;
@@ -445,7 +445,7 @@ namespace NamespaceTests {
public:
void run() {
create();
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id().getKeysFromObject( fromjson( "{a:[{b:[2]}]}" ), keys );
checkSize( 1, keys );
assertEquals( BSON( "" << 2 ), *keys.begin() );
@@ -460,7 +460,7 @@ namespace NamespaceTests {
public:
void run() {
create();
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
ASSERT_EXCEPTION( id().getKeysFromObject( fromjson( "{a:[{b:[1],c:[2]}]}" ), keys ),
UserException );
}
@@ -474,10 +474,10 @@ namespace NamespaceTests {
public:
void run() {
create();
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id().getKeysFromObject( fromjson( "{a:[{b:1},{c:2}]}" ), keys );
checkSize( 2, keys );
- BSONObjSetDefaultOrder::iterator i = keys.begin();
+ BSONObjSet::iterator i = keys.begin();
{
BSONObjBuilder e;
e.appendNull( "" );
@@ -502,7 +502,7 @@ namespace NamespaceTests {
public:
void run() {
create();
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id().getKeysFromObject( fromjson( "{a:[{b:1},{b:[1,2,3]}]}" ), keys );
checkSize( 3, keys );
}
@@ -517,7 +517,7 @@ namespace NamespaceTests {
void run() {
create();
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id().getKeysFromObject( fromjson( "{a:[1,2]}" ), keys );
checkSize(2, keys );
keys.clear();
@@ -541,7 +541,7 @@ namespace NamespaceTests {
void run() {
create();
- BSONObjSetDefaultOrder keys;
+ BSONObjSet keys;
id().getKeysFromObject( fromjson( "{a:1,b:[1,2]}" ), keys );
checkSize(2, keys );
keys.clear();
Please sign in to comment.
Something went wrong with that request. Please try again.