sl@0: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "UB_STD.H" sl@0: sl@0: typedef union sl@0: { sl@0: const TAny* tany; sl@0: const TInt8* tint8; sl@0: const TInt16* tint16; sl@0: const TInt32* tint32; sl@0: const TInt64* tint64; sl@0: const TUint8* tuint8; sl@0: const TUint16* tuint16; sl@0: const TUint32* tuint32; sl@0: } UPTR; sl@0: sl@0: EXPORT_C const TAny* MBtreeKey::Key(const TAny* anEntry) const sl@0: /** Gets the key value for an entry. sl@0: sl@0: @param anEntry Object for which to get the key value sl@0: @return Pointer to the key value */ sl@0: { sl@0: return anEntry; sl@0: } sl@0: sl@0: EXPORT_C TBtreeKey::TBtreeKey(TInt aLength) sl@0: // sl@0: // Discriminating key. Does a raw memory comparison on given length sl@0: // sl@0: : iKeyOffset(0),iCmpType(ECmpNormal8),iKeyLength(aLength) sl@0: {} sl@0: sl@0: EXPORT_C TBtreeKey::TBtreeKey() sl@0: // sl@0: // Discriminating key. Does a raw memory comparison on variable length (byte counted) sl@0: // sl@0: : iKeyOffset(0),iCmpType(ECmpCollated16+1+ECmpNormal8) sl@0: {} sl@0: sl@0: EXPORT_C TBtreeKey::TBtreeKey(TInt anOffset,TKeyCmpText aType) sl@0: // sl@0: // Used to specify a variable length text key, the first character is a count of the actual character data that follows sl@0: // sl@0: : iKeyOffset(anOffset),iCmpType(ECmpCollated16+aType+1) sl@0: { sl@0: switch (aType) sl@0: { sl@0: case ECmpNormal: sl@0: case ECmpFolded: sl@0: case ECmpCollated: sl@0: Panic(EInvalidKeyComparison); sl@0: default: sl@0: break; sl@0: } sl@0: } sl@0: sl@0: EXPORT_C TBtreeKey::TBtreeKey(TInt anOffset,TKeyCmpText aType,TInt aLength) sl@0: // sl@0: // Used for fixed length charecter data. the length is the character count, not the byte size sl@0: // sl@0: : iKeyOffset(anOffset),iCmpType(aType),iKeyLength(aLength) sl@0: { sl@0: switch (aType) sl@0: { sl@0: case ECmpNormal: sl@0: case ECmpFolded: sl@0: case ECmpCollated: sl@0: Panic(EInvalidKeyComparison); sl@0: default: sl@0: break; sl@0: } sl@0: } sl@0: sl@0: EXPORT_C TBtreeKey::TBtreeKey(TInt anOffset,TKeyCmpNumeric aType) sl@0: : iKeyOffset(anOffset),iCmpType(aType) sl@0: { sl@0: switch (aType) sl@0: { sl@0: case ECmpTInt: sl@0: case ECmpTUint: sl@0: Panic(EInvalidKeyComparison); sl@0: default: sl@0: break; sl@0: } sl@0: } sl@0: sl@0: EXPORT_C const TAny* TBtreeKey::Key(const TAny* anEntry) const sl@0: { sl@0: return PtrAdd(anEntry,iKeyOffset); sl@0: } sl@0: sl@0: EXPORT_C TInt TBtreeKey::Compare(const TAny* aLeft,const TAny* aRight) const sl@0: // sl@0: // do the right thing sl@0: // sl@0: { sl@0: UPTR left; sl@0: left.tany=aLeft; sl@0: UPTR right; sl@0: right.tany=aRight; sl@0: switch (iCmpType) sl@0: { sl@0: case ECmpNormal8: sl@0: return Mem::Compare(left.tuint8,iKeyLength,right.tuint8,iKeyLength); sl@0: case ECmpFolded8: sl@0: return Mem::CompareF(left.tuint8,iKeyLength,right.tuint8,iKeyLength); sl@0: case ECmpCollated8: sl@0: return Mem::CompareC(left.tuint8,iKeyLength,right.tuint8,iKeyLength); sl@0: case ECmpNormal16: sl@0: return Mem::Compare(left.tuint16,iKeyLength,right.tuint16,iKeyLength); sl@0: case ECmpFolded16: sl@0: return Mem::CompareF(left.tuint16,iKeyLength,right.tuint16,iKeyLength); sl@0: case ECmpCollated16: sl@0: return Mem::CompareC(left.tuint16,iKeyLength,right.tuint16,iKeyLength); sl@0: case ECmpCollated16+ECmpNormal8+1: sl@0: return Mem::Compare(left.tuint8+1,*left.tuint8,right.tuint8+1,*right.tuint8); sl@0: case ECmpCollated16+ECmpFolded8+1: sl@0: return Mem::CompareF(left.tuint8+1,*left.tuint8,right.tuint8+1,*right.tuint8); sl@0: case ECmpCollated16+ECmpCollated8+1: sl@0: return Mem::CompareC(left.tuint8+1,*left.tuint8,right.tuint8+1,*right.tuint8); sl@0: case ECmpCollated16+ECmpNormal16+1: sl@0: return Mem::Compare(left.tuint16+1,*left.tuint16,right.tuint16+1,*right.tuint16); sl@0: case ECmpCollated16+ECmpFolded16+1: sl@0: return Mem::CompareF(left.tuint16+1,*left.tuint16,right.tuint16+1,*right.tuint16); sl@0: case ECmpCollated16+ECmpCollated16+1: sl@0: return Mem::CompareC(left.tuint16+1,*left.tuint16,right.tuint16+1,*right.tuint16); sl@0: case ECmpTInt8: sl@0: return *left.tint8-*right.tint8; sl@0: case ECmpTUint8: sl@0: return TInt(*left.tuint8)-TInt(*right.tuint8); sl@0: case ECmpTInt16: sl@0: return *left.tint16-*right.tint16; sl@0: case ECmpTUint16: sl@0: return TInt(*left.tuint16)-TInt(*right.tuint16); sl@0: case ECmpTInt32: sl@0: if (*left.tint32<*right.tint32) sl@0: return -1; sl@0: if (*left.tint32>*right.tint32) sl@0: return 1; sl@0: break; sl@0: case ECmpTUint32: sl@0: if (*left.tuint32<*right.tuint32) sl@0: return -1; sl@0: if (*left.tuint32>*right.tuint32) sl@0: return 1; sl@0: break; sl@0: case ECmpTInt64: sl@0: if (*left.tint64<*right.tint64) sl@0: return -1; sl@0: if (*left.tint64>*right.tint64) sl@0: return 1; sl@0: break; sl@0: default: sl@0: break; sl@0: } sl@0: return 0; sl@0: } sl@0: sl@0: EXPORT_C void TBtreeKey::Between(const TAny* aLeft,const TAny* /*aRight*/,TBtreePivot& aPivot) const sl@0: { sl@0: //#pragma message( __FILE__ " : 'TBtreeKey::Between()' whizzy pivot generation not implemented" ) sl@0: UPTR left; sl@0: left.tany=aLeft; sl@0: // UPTR right=(UPTR)aRight; sl@0: switch (iCmpType) sl@0: { sl@0: case ECmpNormal8: sl@0: case ECmpFolded8: sl@0: case ECmpCollated8: sl@0: aPivot.Copy(left.tuint8,iKeyLength); sl@0: break; sl@0: case ECmpNormal16: sl@0: case ECmpFolded16: sl@0: case ECmpCollated16: sl@0: aPivot.Copy(left.tuint8,iKeyLength<<1); sl@0: break; sl@0: case ECmpCollated16+ECmpNormal8+1: sl@0: case ECmpCollated16+ECmpFolded8+1: sl@0: case ECmpCollated16+ECmpCollated8+1: sl@0: aPivot.Copy(left.tuint8,1+*left.tuint8); // include length count sl@0: break; sl@0: case ECmpCollated16+ECmpNormal16+1: sl@0: case ECmpCollated16+ECmpFolded16+1: sl@0: case ECmpCollated16+ECmpCollated16+1: sl@0: aPivot.Copy(left.tuint8,(1+*left.tuint16)<<1); // include length count sl@0: break; sl@0: case ECmpTInt8: sl@0: aPivot.Copy(left.tuint8,sizeof(TInt8)); sl@0: break; sl@0: case ECmpTUint8: sl@0: aPivot.Copy(left.tuint8,sizeof(TUint8)); sl@0: break; sl@0: case ECmpTInt16: sl@0: aPivot.Copy(left.tuint8,sizeof(TInt16)); sl@0: break; sl@0: case ECmpTUint16: sl@0: aPivot.Copy(left.tuint8,sizeof(TUint16)); sl@0: break; sl@0: case ECmpTInt32: sl@0: aPivot.Copy(left.tuint8,sizeof(TInt16)); sl@0: break; sl@0: case ECmpTUint32: sl@0: aPivot.Copy(left.tuint8,sizeof(TUint32)); sl@0: break; sl@0: case ECmpTInt64: sl@0: aPivot.Copy(left.tuint8,sizeof(TInt64)); sl@0: break; sl@0: default: sl@0: break; sl@0: } sl@0: } sl@0: