Beispiel #1
0
int IndexDataKey::compare(const IndexDataKey& other, bool ignoreDuplicates)
{
    ASSERT(m_databaseId >= 0);
    ASSERT(m_objectStoreId >= 0);
    ASSERT(m_indexId >= 0);
    if (int x = compareEncodedIDBKeys(m_encodedUserKey, other.m_encodedUserKey))
        return x;
    if (ignoreDuplicates)
        return 0;
    if (int x = compareEncodedIDBKeys(m_encodedPrimaryKey, other.m_encodedPrimaryKey))
        return x;
    return compareInts(m_sequenceNumber, other.m_sequenceNumber);
}
int compareEncodedIDBKeys(const char*& p, const char* limitA, const char*& q, const char* limitB)
{
    ASSERT(&p != &q);
    ASSERT(p < limitA);
    ASSERT(q < limitB);
    unsigned char typeA = *p++;
    unsigned char typeB = *q++;

    if (int x = IDBKey::compareTypes(keyTypeByteToKeyType(typeA), keyTypeByteToKeyType(typeB)))
        return x;

    switch (typeA) {
    case kIDBKeyNullTypeByte:
    case kIDBKeyMinKeyTypeByte:
        // Null type or max type; no payload to compare.
        return 0;
    case kIDBKeyArrayTypeByte:
        {
            int64_t lengthA, lengthB;
            p = decodeVarInt(p, limitA, lengthA);
            if (!p)
                return 0;
            q = decodeVarInt(q, limitB, lengthB);
            if (!q)
                return 0;
            if (lengthA < 0 || lengthB < 0)
                return 0;
            for (int64_t i = 0; i < lengthA && i < lengthB; ++i) {
                if (int cmp = compareEncodedIDBKeys(p, limitA, q, limitB))
                    return cmp;
            }
            if (lengthA < lengthB)
                return -1;
            if (lengthA > lengthB)
                return 1;
            return 0;
        }
    case kIDBKeyStringTypeByte:
        return compareEncodedStringsWithLength(p, limitA, q, limitB);
    case kIDBKeyDateTypeByte:
    case kIDBKeyNumberTypeByte:
        {
            double d, e;
            p = decodeDouble(p, limitA, &d);
            ASSERT(p);
            q = decodeDouble(q, limitB, &e);
            ASSERT(q);
            if (d < e)
                return -1;
            if (d > e)
                return 1;
            return 0;
        }
    }

    ASSERT_NOT_REACHED();
    return 0;
}
Beispiel #3
0
int compareEncodedIDBKeys(const Vector<char>& keyA, const Vector<char>& keyB)
{
    ASSERT(keyA.size() >= 1);
    ASSERT(keyB.size() >= 1);

    const char* p = keyA.data();
    const char* limitA = p + keyA.size();
    const char* q = keyB.data();
    const char* limitB = q + keyB.size();

    return compareEncodedIDBKeys(p, limitA, q, limitB);
}
Beispiel #4
0
int ExistsEntryKey::compare(const ExistsEntryKey& other)
{
    return compareEncodedIDBKeys(m_encodedUserKey, other.m_encodedUserKey);
}
Beispiel #5
0
int ObjectStoreDataKey::compare(const ObjectStoreDataKey& other)
{
    return compareEncodedIDBKeys(m_encodedUserKey, other.m_encodedUserKey);
}