1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/store/INC/S32BTREE.INL Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,180 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +// Class TBtreeToken
1.20 +inline TBtreeToken::TBtreeToken(TEmpty)
1.21 +/** Constructor that intialises the TBtreeToken for an empty B-tree.
1.22 +
1.23 +@param Intialises for an empty B-tree */
1.24 + {Clear();}
1.25 +inline void TBtreeToken::Touch()
1.26 +/** Marks the B-tree as broken. */
1.27 + {iHeight=0;}
1.28 +inline TBool TBtreeToken::IsBroken() const
1.29 +/** Tests if the broken flag has been set on the B-tree.
1.30 +
1.31 +@return True if the B-tree is broken, otherwise false. */
1.32 + {return iFirst!=KNullPageRef&&iHeight==0;}
1.33 +inline TBool TBtreeToken::IsIntact() const
1.34 +/** Tests if the broken flag has not been set on the B-tree .
1.35 +
1.36 +@return True if the B-tree is not broken, otherwise false. */
1.37 + {return iFirst==KNullPageRef||iHeight!=0;}
1.38 +inline TBool TBtreeToken::IsEmpty() const
1.39 +/** Tests if the B-tree is empty.
1.40 +
1.41 +@return True if the B-tree is empty, otherwise false. */
1.42 + {return iFirst==KNullPageRef;}
1.43 +
1.44 +// Class TBtreePath
1.45 +inline TBtreePath::TBtreePath()
1.46 + : iEnd(-1)
1.47 + {}
1.48 +inline TPageRef TBtreePath::Node() const
1.49 + {return iNodes[iEnd];}
1.50 +inline TInt TBtreePath::Entry() const
1.51 + {return iEntries[iEnd];}
1.52 +inline TBool TBtreePath::IsLeaf() const
1.53 + {return iEnd==0;}
1.54 +inline TBtreeHeight TBtreePath::End() const
1.55 + {return iEnd;}
1.56 +inline void TBtreePath::SetEntry(TInt aEntry)
1.57 + {iEntries[iEnd]=TUint8(aEntry);}
1.58 +inline void TBtreePath::Pop()
1.59 + {++iEnd;}
1.60 +
1.61 +// Class TBtree
1.62 +inline TBool TBtree::IsDirty() const
1.63 +/** Tests if the dirty flag has been set on the B-tree.
1.64 +
1.65 +Any updates to the B-tree will set this flag on the TBtree object. Applications
1.66 +can use this to determine if they need to flush the page pool and re-save
1.67 +the B-tree token, after which they can call MarkCurrent() to indicate that
1.68 +the persistent storage is now up-to-date with the TBtree object.
1.69 +
1.70 +@return True if the dirty flag has been set, otherwise false */
1.71 + {return iStatus<0;}
1.72 +inline void TBtree::MarkCurrent()
1.73 +/** Clears the dirty flag. */
1.74 + {iStatus&=~EDirty;}
1.75 +inline void TBtree::MarkDirty()
1.76 +/** Sets the dirty flag. */
1.77 + {iStatus|=EDirty;}
1.78 +inline TBool TBtree::IsBroken() const
1.79 +/** Tests if the broken flag has been set on the B-tree.
1.80 +
1.81 +Any updates to the B-tree that fail will leave this flag set on the TBtree
1.82 +object. This indicates that the persistent tree data is broken (corrupt) and
1.83 +the tree needs to be repaired. In this state, none of the functions which
1.84 +use a TBtreePos will work, only those taking a TBtreeMark.
1.85 +
1.86 +@return True if the B-tree is broken, otherwise false. */
1.87 + {return (iStatus&EBroken)!=0;}
1.88 +inline TBool TBtree::IsIntact() const
1.89 +/** Tests if the broken flag has not been set on the B-tree .
1.90 +
1.91 +@return True if the B-tree is not broken, otherwise false. */
1.92 + {return (iStatus&EBroken)==0;}
1.93 +inline void TBtree::MarkBroken()
1.94 +/** Sets the broken flag. */
1.95 + {if (iFirst!=KNullPageRef) iStatus|=EBroken;}
1.96 +inline TBool TBtree::IsEmpty() const
1.97 +/** Tests if the B-tree is empty.
1.98 +
1.99 +@return True if the B-tree is empty, otherwise false */
1.100 + {return iFirst==KNullPageRef;}
1.101 +
1.102 +// Template class TBtreeFix
1.103 +template <class Entry,class Key>
1.104 +inline TBtreeFix<Entry,Key>::TBtreeFix(TBtreeMode aMode)
1.105 + : TBtreeFixBase(aMode,sizeof(Entry),sizeof(Key))
1.106 +/** Constructor that sets the B-tree mode.
1.107 +
1.108 +@param aMode B-tree operating mode */
1.109 + {}
1.110 +template <class Entry,class Key>
1.111 +inline TBtreeFix<Entry,Key>::TBtreeFix(const TBtreeToken& aToken,TBtreeMode aMode)
1.112 + : TBtreeFixBase(aToken,aMode,sizeof(Entry),sizeof(Key))
1.113 +/** Constructor that sets the B-tree mode and initialisation parameters.
1.114 +
1.115 +@param aToken Parameters with which to initialise the B-tree
1.116 +@param aMode B-tree operating mode */
1.117 + {}
1.118 +template <class Entry,class Key>
1.119 +inline TBool TBtreeFix<Entry,Key>::FindL(TBtreePos& aPos,const Key& aKey,TBtree::TFind aMode) const
1.120 + {return TBtreeFixBase::FindL(aPos,&aKey,aMode);}
1.121 +template <class Entry,class Key>
1.122 +inline TBool TBtreeFix<Entry,Key>::InsertL(TBtreePos& aPos,const Entry& anEntry,TAllowDuplicates aDup)
1.123 +/** Inserts an entry into the tree.
1.124 +
1.125 +@param aPos On return, the position of the entry inserted
1.126 +@param anEntry Entry to insert
1.127 +@param aDup Flag to indicate whether duplicate entries are allowed in the tree
1.128 +@return True if successful, false if the entry was a duplicate and aDup was
1.129 +set to ENoDuplicates */
1.130 + {return TBtreeFixBase::InsertL(aPos,&anEntry,aDup);}
1.131 +template <class Entry,class Key>
1.132 +inline TBool TBtreeFix<Entry,Key>::DeleteL(const Key& aKey)
1.133 +/** Delete an entry.
1.134 +
1.135 +@param aKey Key of the entry to delete
1.136 +@return True if successful, false if the entry was not found */
1.137 + {return TBtreeFixBase::DeleteL(&aKey);}
1.138 +template <class Entry,class Key>
1.139 +inline Entry TBtreeFix<Entry,Key>::AtL(const TBtreePos& aPos) const
1.140 +/** Gets the entry at the specified position.
1.141 +
1.142 +@param aPos Position of the entry to get
1.143 +@return Entry at position aPos */
1.144 + {Entry e;TBtreeFixBase::ExtractAtL(aPos,&e);return e;}
1.145 +template <class Entry,class Key>
1.146 +inline Entry TBtreeFix<Entry,Key>::AtL(const TBtreeMark& aMark) const
1.147 +/** Gets the entry at the specified iterator position.
1.148 +
1.149 +@param aMark Iterator to use to get the entry
1.150 +@return Entry at current iterator position */
1.151 + {Entry e;TBtreeFixBase::ExtractAtL(aMark,&e);return e;}
1.152 +template <class Entry,class Key>
1.153 +inline void TBtreeFix<Entry,Key>::ExtractAtL(const TBtreePos& aPos,Entry& anEntry) const
1.154 +/** Gets the entry at the specified position.
1.155 +
1.156 +@param aPos Position of the entry to get
1.157 +@param anEntry On return, the specified entry */
1.158 + {TBtreeFixBase::ExtractAtL(aPos,&anEntry);}
1.159 +template <class Entry,class Key>
1.160 +inline void TBtreeFix<Entry,Key>::ExtractAtL(const TBtreeMark& aMark,Entry& anEntry) const
1.161 +/** Gets the entry at the specified iterator position.
1.162 +
1.163 +@param aMark Iterator to use to get the entry
1.164 +@param anEntry On return, the specified entry */
1.165 + {TBtreeFixBase::ExtractAtL(aMark,&anEntry);}
1.166 +inline TBtreeFix<TAny,TAny>::TBtreeFix(TBtreeMode aMode,TInt anEntrySize,TInt aKeySize)
1.167 + : TBtreeFixBase(aMode,anEntrySize,aKeySize)
1.168 +/** Constructor that sets the B-tree mode.
1.169 +
1.170 +@param aMode B-tree operating mode
1.171 +@param anEntrySize Entry size
1.172 +@param aKeySize Key size for entries */
1.173 + {}
1.174 +inline TBtreeFix<TAny,TAny>::TBtreeFix(const TBtreeToken& aToken,TBtreeMode aMode,TInt anEntrySize,TInt aKeySize)
1.175 + : TBtreeFixBase(aToken,aMode,anEntrySize,aKeySize)
1.176 +/** Constructor that sets the B-tree mode and initialisation parameters.
1.177 +
1.178 +@param aToken Parameters with which to initialise the B-tree
1.179 +@param aMode B-tree operating mode
1.180 +@param anEntrySize Entry size
1.181 +@param aKeySize Key size for entries */
1.182 + {}
1.183 +