Exemplo n.º 1
0
Arquivo: key.cpp Projeto: kzys/mongo
bool KeyV1::woEqual(const KeyV1& right) const {
    const unsigned char *l = _keyData;
    const unsigned char *r = right._keyData;

    if( (*l|*r) == IsBSON ) {
        return toBson().equal(right.toBson());
    }

    while( 1 ) {
        char lval = *l;
        char rval = *r;
        if( (lval&(cCANONTYPEMASK|cHASMORE)) != (rval&(cCANONTYPEMASK|cHASMORE)) )
            return false;
        l++;
        r++;
        switch( lval&cCANONTYPEMASK ) {
        case coid:
            if( *((unsigned*) l) != *((unsigned*) r) )
                return false;
            l += 4;
            r += 4;
        case cdate:
        case cdouble:
            if( *((unsigned long long *) l) != *((unsigned long long *) r) )
                return false;
            l += 8;
            r += 8;
            break;
        case cstring:
        {
            unsigned sz = ((unsigned) *l) + 1;
            if( memcmp(l, r, sz) ) // first byte checked is the length byte
                return false;
            l += sz;
            r += sz;
            break;
        }
        case cbindata:
        {
            int len = binDataCodeToLength(*l) + 1;
            if( memcmp(l, r, len) )
                return false;
            l += len;
            r += len;
            break;
        }
        case cminkey:
        case cnull:
        case cfalse:
        case ctrue:
        case cmaxkey:
            break;
        default:
            assert(false);
        }
        if( (lval&cHASMORE) == 0 )
            break;
    }
    return true;
}
Exemplo n.º 2
0
    bool KeyV1::woEqual(const KeyV1& right) const {
        const unsigned char *l = _keyData;
        const unsigned char *r = right._keyData;

        if( (*l|*r) == IsBSON ) {
            return toBson().equal(right.toBson());
        }

        while( 1 ) { 
            char lval = *l; 
            char rval = *r;
            if( (lval&(cCANONTYPEMASK|cHASMORE)) != (rval&(cCANONTYPEMASK|cHASMORE)) )
                return false;
            l++; r++;
            switch( lval&cCANONTYPEMASK ) { 
            case coid:
                if( *((unsigned*) l) != *((unsigned*) r) )
                    return false;
                l += 4; r += 4;
            case cdate:
                if( *((unsigned long long *) l) != *((unsigned long long *) r) )
                    return false;
                l += 8; r += 8;
                break;
            case cdouble:
                if( (reinterpret_cast< const PackedDouble* > (l))->d != (reinterpret_cast< const PackedDouble* >(r))->d )
                    return false;
                l += 8; r += 8;
                break;
            case cstring:
                {
                    if( *l != *r ) 
                        return false; // not same length
                    unsigned sz = ((unsigned) *l) + 1;
                    if( memcmp(l, r, sz) )
                        return false;
                    l += sz; r += sz;
                    break;
                }
            case cbindata:
                {
                    if( *l != *r )
                        return false; // len or subtype mismatch
                    int len = binDataCodeToLength(*l) + 1;
                    if( memcmp(l, r, len) ) 
                        return false;
                    l += len; r += len;
                    break;
                }
            case cminkey:
            case cnull:
            case cfalse:
            case ctrue:
            case cmaxkey:
                break;
            default:
                verify(false);
            }
            if( (lval&cHASMORE) == 0 )
                break;
        }
        return true;
    }
Exemplo n.º 3
0
 // at least one of this and right are traditional BSON format
 int NOINLINE_DECL KeyV1::compareHybrid(const KeyV1& right, const Ordering& order) const { 
     BSONObj L = toBson();
     BSONObj R = right.toBson();
     return L.woCompare(R, order, /*considerfieldname*/false);
 }