Changeset 19678


Ignore:
Timestamp:
02/08/12 18:11:17 (4 months ago)
Author:
sys
Message:

Tree en cours...

Location:
trunk/Jav_Orient
Files:
1 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Jav_Orient/src/eu/scenari/orient/recordstruct/lib/tree/ValueTree.java

    r19672 r19678  
    9292                fStruct = pStruct; 
    9393                fRootEntry = pReader.getAsValue(); 
    94                 fSize = getTreeStorageConfig().isSizeStored() ? pReader.getAsInteger() : -1; 
     94                fSize = pReader.getAsInteger(); 
     95                if (!getTreeStorageConfig().isSizeStored()) fSize = SIZE_UNKNOWN; 
    9596                fPojo = new Tree(this, getTreeStorageConfig().getKeyComparator(), getTreeStorageConfig().getBalancingLayout()); 
    9697        } 
     
    111112 
    112113        public void setSizeByDelta(int pDelta) { 
     114                if (fSize == SIZE_UNKNOWN) return; 
    113115                fSize += pDelta; 
    114116                if (getTreeStorageConfig().isSizeStored()) { 
     
    204206                        ((IRecordStructInternal) getRecord()).addSubRecordDirty(this); 
    205207                } 
     208                assert (!fNodesToSave.contains(pNode)); 
    206209                fNodesToSave.add(pNode); 
    207210        } 
     
    209212        /** Called by rakes and slots. */ 
    210213        public void addNodeToDelete(IRecordStruct<?> pNode) { 
    211                 if (pNode.isDirty() && fNodesToSave != null) { 
     214                if (fNodesToSave != null) { 
    212215                        for (int i = 0; i < fNodesToSave.size(); i++) { 
    213216                                if (fNodesToSave.get(i) == pNode) { 
  • trunk/Jav_Orient/src/eu/scenari/orient/recordstruct/lib/tree/ValueTreeNode.java

    r19672 r19678  
    4343import eu.scenari.orient.recordstruct.IValueList; 
    4444import eu.scenari.orient.recordstruct.IValueOwner; 
    45 import eu.scenari.orient.recordstruct.impl.StructReader; 
    4645import eu.scenari.orient.recordstruct.value.ValueUpdatableAbstract; 
    4746import eu.scenari.orient.tree.provider.ITreeNodeProvider; 
     
    5958        } 
    6059 
    61         public ValueTreeNode(StructReader pReader, IValueOwner pOwner) { 
    62                 super(pOwner, false); 
     60        public ValueTreeNode(IValueOwner pOwner, boolean pIsDirty) { 
     61                super(pOwner, pIsDirty); 
    6362        } 
    6463 
     
    7978        } 
    8079 
     80        public void deleteNode() { 
     81                fTree.addNodeToDelete(this.getRecord()); 
     82                fKeys.clear(); 
     83        } 
     84 
    8185        // ############# 
    8286 
  • trunk/Jav_Orient/src/eu/scenari/orient/recordstruct/lib/tree/ValueTreeRake.java

    r19672 r19678  
    7171 
    7272        public ValueTreeRake(StructReader pReader, IValueOwner pOwner) { 
    73                 super(pReader, pOwner); 
     73                super(pOwner, false); 
     74                pReader.pushOwner(this); 
    7475                fKeys = pReader.getAsValue(); 
    7576                fSubNodes = pReader.getAsValue(); 
     77                pReader.popOwner(); 
    7678        } 
    7779 
     
    143145        } 
    144146 
    145         public void deleteNode() { 
    146                 fTree.addNodeToDelete(this.getRecord()); 
    147                 //free mem 
    148                 fKeys = null; 
    149                 fSubNodes = null; 
    150         } 
    151  
    152147        // ############# 
    153148 
     
    187182        } 
    188183 
     184        public void deleteNode() { 
     185                super.deleteNode(); 
     186                fSubNodes.clear(); 
     187        } 
     188 
    189189        // ############# 
    190190 
  • trunk/Jav_Orient/src/eu/scenari/orient/recordstruct/lib/tree/ValueTreeSlotKV.java

    r19672 r19678  
    6565 
    6666        public ValueTreeSlotKV(StructReader pReader, IValueOwner pOwner) { 
    67                 super(pReader, pOwner); 
     67                super(pOwner, false); 
     68                pReader.pushOwner(this); 
    6869                fKeys = pReader.getAsValue(); 
    6970                fValues = pReader.getAsValue(); 
     71                pReader.popOwner(); 
    7072        } 
    7173 
     
    137139        } 
    138140 
    139         public void deleteNode() { 
    140                 fTree.addNodeToDelete(this.getRecord()); 
    141                 //free mem 
    142                 fKeys = null; 
    143                 fValues = null; 
    144         } 
    145  
    146141        // ############# 
    147142 
     
    161156                fValues.set(pOffset, pValue); 
    162157                return true; 
     158        } 
     159 
     160        public void deleteNode() { 
     161                super.deleteNode(); 
     162                fValues.clear(); 
    163163        } 
    164164 
  • trunk/Jav_Orient/src/eu/scenari/orient/recordstruct/value/ValueListImmutableFixed.java

    r19674 r19678  
    332332                        isolateBufferForUpdates(fSize - 1); 
    333333                        int vOffset = index2Offset(pIndex); 
    334                         System.arraycopy(fRawEntries, vOffset + getFixedLengthEntry(), fRawEntries, vOffset, (pIndex - fSize - 1) * getFixedLengthEntry()); 
     334                        System.arraycopy(fRawEntries, vOffset + getFixedLengthEntry(), fRawEntries, vOffset, (fSize - pIndex - 1) * getFixedLengthEntry()); 
    335335                } else { 
    336336                        setDirty(); 
  • trunk/Jav_Orient/src/eu/scenari/orient/tree/impl/BalancedLayout.java

    r19675 r19678  
    149149                if (pNode.fParent != null && pNode.fProvider.getFillRate() < fOptimizeThreshold) { 
    150150                        //pNode become too empty, try to merge with a neighbour 
    151                         tryToDelete(pNode); 
     151                        if (pNode.isRake()) { 
     152                                tryToDeleteRake((TreeRake<K, V>) pNode); 
     153                        } else { 
     154                                tryToDeleteSlot((TreeSlot<K, V>) pNode); 
     155                        } 
    152156                } 
    153157        } 
     
    157161        } 
    158162 
    159         protected <K, V> void tryToDelete(TreeNode<K, V> pNode) { 
    160                 TreeRake<K, V> vParent = pNode.fParent; 
    161                 int vOffset = pNode.getOffsetInParent(); 
    162                 if (vOffset > 0) { 
    163                         TreeNode<K, V> vPreviousNode = vParent.getNodeIfLoaded(vOffset - 1); 
    164                         if (vPreviousNode != null && vPreviousNode.getProvider().getFillRate() < fFillingThreshold && pNode.isRake() == vPreviousNode.isRake()) { 
    165                                 //Try to merge 
    166                                 if (vPreviousNode.adoptAllEntriesFromRight(pNode)) { 
    167                                         pNode.deleteNode(); 
    168                                         return; 
    169                                 } 
    170                         } 
    171                 } 
    172                 int vIndexLastSlotInRake = vParent.getProvider().getSize() - 1; 
    173                 if (vOffset < vIndexLastSlotInRake) { 
    174                         TreeNode<K, V> vNextNode = vParent.getNodeIfLoaded(vOffset + 1); 
    175                         if (vNextNode != null && vNextNode.getProvider().getFillRate() < fFillingThreshold && pNode.isRake() == vNextNode.isRake()) { 
    176                                 //Try to merge 
    177                                 if (vNextNode.adoptAllEntriesFromLeft(pNode)) { 
    178                                         pNode.deleteNode(); 
    179                                         return; 
    180                                 } 
    181                         } 
    182                 } 
    183                 if (vOffset == 0) { 
    184                         //TODO Try with previous slot in the previous rake. 
    185                 } 
    186                 if (vOffset == vIndexLastSlotInRake) { 
    187                         //TODO Try with next slot in the next rake. 
     163        protected <K, V> void tryToDeleteSlot(TreeSlot<K, V> pNode) { 
     164                TreeSlot<K, V> vLeftNode = pNode.findLeftSlot(); 
     165                if (vLeftNode != null && vLeftNode.getProvider().getFillRate() < fFillingThreshold) { 
     166                        //Try to merge 
     167                        if (vLeftNode.adoptAllEntriesFromRight(pNode)) { 
     168                                pNode.deleteNode(); 
     169                                return; 
     170                        } 
     171                } 
     172                TreeSlot<K, V> vRightNode = pNode.findRightSlot(); 
     173                if (vRightNode != null && vRightNode.getProvider().getFillRate() < fFillingThreshold) { 
     174                        //Try to merge 
     175                        if (vRightNode.adoptAllEntriesFromLeft(pNode)) { 
     176                                pNode.deleteNode(); 
     177                                return; 
     178                        } 
     179                } 
     180        } 
     181 
     182        protected <K, V> void tryToDeleteRake(TreeRake<K, V> pNode) { 
     183                TreeNode<K, V> vLeftNode = pNode.fParent.findLeftCousin(pNode.getOffsetInParent()); 
     184                if (vLeftNode != null && vLeftNode.getProvider().getFillRate() < fFillingThreshold && vLeftNode.isRake()) { 
     185                        //Try to merge 
     186                        if (vLeftNode.adoptAllEntriesFromRight(pNode)) { 
     187                                pNode.deleteNode(); 
     188                                return; 
     189                        } 
     190                } 
     191                TreeNode<K, V> vRightNode = pNode.fParent.findRightCousin(pNode.getOffsetInParent()); 
     192                if (vRightNode != null && vRightNode.getProvider().getFillRate() < fFillingThreshold && vRightNode.isRake()) { 
     193                        //Try to merge 
     194                        if (vRightNode.adoptAllEntriesFromLeft(pNode)) { 
     195                                pNode.deleteNode(); 
     196                                return; 
     197                        } 
    188198                } 
    189199        } 
  • trunk/Jav_Orient/src/eu/scenari/orient/tree/impl/Tree.java

    r19675 r19678  
    222222        } 
    223223 
     224        public boolean isEmpty() { 
     225                int vSize = fProvider.getSize(); 
     226                if (vSize > 0) return false; 
     227                if (vSize == 0) return true; 
     228                //Size unknown 
     229                TreeSlot<K, V> vSlot = findFirstSlot(); 
     230                while (vSlot != null && vSlot.getSize() == 0) { 
     231                        vSlot = vSlot.findRightSlot(); 
     232                } 
     233                return vSlot == null; 
     234        } 
     235 
    224236        public Set<Entry<K, V>> entrySet() { 
    225237                final EntrySet vResult = fEntrySet; 
  • trunk/Jav_Orient/src/eu/scenari/orient/tree/impl/TreeNode.java

    r19674 r19678  
    6060 
    6161        public void deleteNode() { 
    62                 // remove form parent 
    6362                if (fParent != null) { 
     63                        // remove from parent 
    6464                        fParent.removeChildNode(this); 
    65                 } else { 
    66                         fTree.fBalancingLayout.onRemovedEntry(this); 
    6765                } 
    6866                // Delete this node. 
  • trunk/Jav_Orient/src/eu/scenari/orient/tree/impl/TreeRake.java

    r19674 r19678  
    257257        public void removeChildNode(TreeNode pEntry) { 
    258258                assert (pEntry.fParent == this); 
    259                 int vOffsetEntry = pEntry.getOffsetInParent(); 
    260                 if (vOffsetEntry == 0 && fProvider.getSize() == 1) { 
    261                         // Last entry in this slot, cleanup 
     259                int vOldSize = fProvider.getSize(); 
     260                if (vOldSize == 1) { 
     261                        assert (pEntry.getOffsetInParent() == 0); 
     262                        // Last entry in this rake, cleanup 
    262263                        if (fParent != null) { 
    263                                 fParent.removeChildNode(this); 
     264                                deleteNode(); 
    264265                        } else { 
    265266                                // We are the root, no more entries, we ref the last empty slot as root. 
    266                                 TreeSlot vSlot = pEntry.findFirstSlot(); 
     267                                TreeSlot<K, V> vSlot = pEntry.findFirstSlot(); 
    267268                                vSlot.setParent(null, 0); 
     269                                vSlot.clear(); 
    268270                                fTree.setRoot(vSlot); 
    269                         } 
    270                         if (pEntry.fParent == this) { 
    271                                 // Delete the entry if it has not been setted elsewhere. 
    272                                 pEntry.fProvider.deleteNode(); 
    273271                        } 
    274272                } else { 
    275273                        // Remove this entry. 
     274                        int vOffsetEntry = pEntry.getOffsetInParent(); 
     275                        assert (vOffsetEntry < vOldSize); 
     276                        for (int i = vOffsetEntry; i < vOldSize - 1; i++) { 
     277                                TreeNode<K, V> vNext = fChildren[i + 1]; 
     278                                fChildren[i] = vNext; 
     279                                vNext.setParent(this, i); 
     280                        } 
     281                        fChildren[vOldSize - 1] = null; 
    276282                        fProvider.remove(vOffsetEntry); 
    277283                        // Update start key. 
  • trunk/Jav_Orient/src/eu/scenari/orient/tree/impl/TreeSlot.java

    r19675 r19678  
    9393 
    9494        public void removeEntry(int pOffset) { 
    95                 assert (pOffset > 0 && pOffset < getProvider().getSize()); 
    96                 if (pOffset == 0 && fProvider.getSize() == 1) { 
     95                assert (pOffset >= 0 && pOffset < getProvider().getSize()); 
     96                if (pOffset == 0 && fProvider.getSize() == 1 && fParent != null) { 
    9797                        //cleanup 
    9898                        deleteNode(); 
     
    103103                        } 
    104104                        fTree.fBalancingLayout.onRemovedEntry(this); 
     105                } 
     106        } 
     107 
     108        /** Called when this is last slot and setted on tree root. */ 
     109        public void clear() { 
     110                for (int i = getSize() - 1; i >= 0; i--) { 
     111                        fProvider.remove(i); 
    105112                } 
    106113        } 
  • trunk/Jav_Orient/src/eu/scenari/orient/tree/provider/ITreeProvider.java

    r19672 r19678  
    22 
    33public interface ITreeProvider<K, V> { 
     4 
     5        public static int SIZE_UNKNOWN = -1; 
    46 
    57        /**  
     
    79         * A provider can not store the current size and then return -1. 
    810         *  
    9          * @return tree size or -1 if size unknown. 
     11         * @return tree size or {@link #SIZE_UNKNOWN} if size unknown. 
    1012         */ 
    1113        public int getSize(); 
     
    1719 
    1820        /** 
    19          * Set size. 
    20          * Can be called when {@link #getSize()} has returned -1 and the size 
     21         * Set computed size. 
     22         * Can be called when {@link #getSize()} has returned {@link #SIZE_UNKNOWN} and the size 
    2123         * has been computed by iterating the tree.  
    22          * The size should then be kept in memory for performance. 
     24         * The size should then be kept and updated in memory for performance. 
    2325         */ 
    2426        public void setSize(int pComputedSize); 
  • trunk/Jav_Orient/test/eu/scenari/orient/tree/FactorySequentialLong.java

    r19675 r19678  
    77import junit.framework.Assert; 
    88import eu.scenari.commons.util.collections.IteratorBufferedNextBase; 
     9import eu.scenari.commons.util.lang.ScException; 
    910 
    1011public class FactorySequentialLong implements IKeyFactory<Long>, IValueFactory<Long> { 
     
    1617        protected AtomicLong fCounter = new AtomicLong(fStartValue); 
    1718 
     19        protected UnorderedIterator fRemovedKeys; 
     20 
     21        public class UnorderedIterator extends IteratorBufferedNextBase<Long> { 
     22 
     23                protected int fBase; 
     24 
     25                protected long fSize; 
     26 
     27                protected long fCurrentStep = 0; 
     28 
     29                protected long fCurrentModulo = 0; 
     30 
     31                public UnorderedIterator(int pSizeStep) { 
     32                        fBase = pSizeStep; 
     33                        fSize = fCounter.get(); 
     34                } 
     35 
     36                public boolean hasNext() { 
     37                        //Si le suivant a déjà été trouvé, il doit d'abord etre lu par next(). 
     38                        if (fNext != null) return true; 
     39                        //Cherche à renseigner fNext 
     40                        do { 
     41                                while (fCurrentModulo < fBase) { 
     42                                        long vNext = fStartValue + fCurrentStep + fCurrentModulo; 
     43                                        if (vNext < fSize) { 
     44                                                fNext = vNext; 
     45                                                fCurrentStep += fBase; 
     46                                                break; 
     47                                        } else { 
     48                                                fCurrentModulo++; 
     49                                                fCurrentStep = 0; 
     50                                        } 
     51                                } 
     52                                if (fNext != null && fRemovedKeys != null && fRemovedKeys != this && fRemovedKeys.isAlreadyReturned(fNext)) { 
     53                                        fNext = null; 
     54                                } else { 
     55                                        break; 
     56                                } 
     57                        } while (true); 
     58                        return (fNext != null); 
     59                } 
     60 
     61                public boolean isAlreadyReturned(Long pEntry) { 
     62                        long vModulo = (pEntry.longValue() - fStartValue) % (long) fBase; 
     63                        if (vModulo > fCurrentModulo) return false; 
     64                        if (vModulo < fCurrentModulo) return true; 
     65                        long vStep = (pEntry.longValue() - fStartValue) / (long) fBase; 
     66                        return (vStep * fBase) < fCurrentStep; 
     67                } 
     68 
     69        } 
     70 
    1871        public Long newKey() { 
     72                if (fRemovedKeys != null) throw new ScException("Removes keys is started, create new keys not allowed."); 
    1973                return fCounter.getAndIncrement(); 
    2074        } 
     
    2579 
    2680        public Iterator<Long> unorderedIterator() { 
    27                 return null; 
     81                return new UnorderedIterator(27); 
    2882        } 
    2983 
     
    3690                                if (fNext != null) return true; 
    3791                                //Cherche à renseigner fNext 
    38                                 if (fLast < fCounter.get()) { 
     92                                while (fLast < fCounter.get()) { 
    3993                                        fNext = fLast++; 
     94                                        if (fRemovedKeys != null && fRemovedKeys.isAlreadyReturned(fNext)) { 
     95                                                fNext = null; 
     96                                        } else { 
     97                                                break; 
     98                                        } 
    4099                                } 
    41100                                return (fNext != null); 
    42101                        } 
    43102                }; 
     103        } 
     104 
     105        public Long getUnorderedKeyToRemove() { 
     106                if (fRemovedKeys == null) fRemovedKeys = new UnorderedIterator(37); 
     107                return fRemovedKeys.hasNext() ? fRemovedKeys.next() : null; 
    44108        } 
    45109 
  • trunk/Jav_Orient/test/eu/scenari/orient/tree/IKeyFactory.java

    r19672 r19678  
    77        public K newKey(); 
    88 
    9         public K peekRandomKey(); 
     9        public Iterator<K> creationOrderIterator(); 
    1010 
    1111        public Iterator<K> unorderedIterator(); 
    1212 
    13         public Iterator<K> creationOrderIterator(); 
     13        public K peekRandomKey(); 
     14 
     15        public K getUnorderedKeyToRemove(); 
     16 
    1417} 
  • trunk/Jav_Orient/test/eu/scenari/orient/tree/TreeBasicTest.java

    r19675 r19678  
    5959public class TreeBasicTest extends TestDbAbstract { 
    6060 
    61         public static final TreeStorageConfig TREECONFIG = new TreeStorageConfig().setKeysStruct(TypesBase.LIST_LONG).setValuesStruct(TypesBase.LIST_LONG).setSizeStored(false).setBalancingLayout(IBalancingLayout.DEFAULT_BALANCED_INCREMENTAL_INSERT) 
    62                         .setRakeCapacity(256).setSlotCapacity(256); 
     61        public static int MAP_SIZE = 2000; 
     62 
     63        public static boolean STORE_SIZE = false; 
     64 
     65        public static final TreeStorageConfig TREECONFIG = new TreeStorageConfig().setKeysStruct(TypesBase.LIST_LONG).setValuesStruct(TypesBase.LIST_LONG).setSizeStored(STORE_SIZE).setBalancingLayout(IBalancingLayout.DEFAULT_BALANCED_INCREMENTAL_INSERT) 
     66                        .setRakeCapacity(32).setSlotCapacity(32); 
    6367 
    6468        public static final StructTree TREE_LONG_LONG = new StructTree(new ExtendedStructId(1, 1), "trreeLongLong").setTreeConfig(TREECONFIG); 
     
    7276        @Test 
    7377        public void test1() { 
    74                 int vSize = 200000; 
     78                int vSize = MAP_SIZE; 
    7579                fDatabase = fDbDriver.acquireDatabase(); 
    7680                IRecordStruct<ValueTree<Long, Long>> vRecord = fDatabase.newInstance(); 
     
    7983                ORID vId = vRecord.getIdentity(); 
    8084 
     85                //Inserts 
    8186                Map<Long, Long> vTree = vRecord.getValue().getPojo(); 
    8287                for (int i = 1; i <= vSize; i++) { 
     
    8489                        vTree.put(vKey, fFactorySeqLong.newValueFor(vKey)); 
    8590                        vRecord.save(); 
    86                         Assert.assertEquals(i, vTree.size()); 
     91                        checkSize(vTree, i); 
    8792                } 
    88                 Assert.assertEquals(vSize, vTree.size()); 
     93                checkSize(vTree, vSize); 
     94                checkEntrySetIterator(vTree); 
    8995                checkAllEntries(vTree); 
    9096 
     97                //Sequential access 
    9198                forceNewDatabase(); 
    9299                vRecord = fDatabase.load(vId); 
    93100                vTree = vRecord.getValue().getPojo(); 
    94                 Assert.assertEquals(vSize, vTree.size()); 
     101                checkSize(vTree, vSize); 
    95102                checkAllEntries(vTree); 
    96103 
     104                //Unordered access 
     105                forceNewDatabase(); 
     106                vRecord = fDatabase.load(vId); 
     107                vTree = vRecord.getValue().getPojo(); 
     108                for (Iterator<Long> vIt = fFactorySeqLong.unorderedIterator(); vIt.hasNext();) { 
     109                        Long vKey = vIt.next(); 
     110                        fFactorySeqLong.checkValueForKey(vKey, vTree.get(vKey)); 
     111                } 
     112 
     113                //Remove entries 
     114                forceNewDatabase(); 
     115                vRecord = fDatabase.load(vId); 
     116                vTree = vRecord.getValue().getPojo(); 
     117                Long vKey = fFactorySeqLong.getUnorderedKeyToRemove(); 
     118                while (vKey != null) { 
     119                        //System.out.println(vKey); 
     120                        vTree.remove(vKey); 
     121                        vRecord.save(); 
     122                        //                      forceNewDatabase(); 
     123                        //                      vRecord = fDatabase.load(vId); 
     124                        //                      vTree = vRecord.getValue().getPojo(); 
     125                        //                      checkSize(vTree, --vSize); 
     126                        //                      checkAllEntries(vTree); 
     127                        vKey = fFactorySeqLong.getUnorderedKeyToRemove(); 
     128                } 
     129                Assert.assertTrue(vTree.isEmpty()); 
    97130        } 
    98131 
    99         protected void checkAllEntries(Map<Long, Long> pTree) { 
     132        protected void checkSize(Map<Long, Long> pTree, int pSize) { 
     133                if (STORE_SIZE) { 
     134                        Assert.assertEquals(pTree.size(), pSize); 
     135                } 
     136        } 
     137 
     138        protected void checkEntrySetIterator(Map<Long, Long> pTree) { 
    100139                int vCount = 0; 
    101140                for (Map.Entry<Long, Long> vEntry : pTree.entrySet()) { 
     
    103142                        vCount++; 
    104143                } 
    105                 Assert.assertEquals(pTree.size(), vCount); 
     144                checkSize(pTree, vCount); 
     145        } 
     146 
     147        protected void checkAllEntries(Map<Long, Long> pTree) { 
     148                int vCount = 0; 
    106149                for (Iterator<Long> vIt = fFactorySeqLong.creationOrderIterator(); vIt.hasNext();) { 
    107150                        Long vKey = vIt.next(); 
    108151                        fFactorySeqLong.checkValueForKey(vKey, pTree.get(vKey)); 
     152                        vCount++; 
    109153                } 
     154                checkSize(pTree, vCount); 
    110155 
    111156        } 
  • trunk/Jav_Orient/test/eu/scenari/orient/tree/perf/MVRBTreePerfTest.java

    r19675 r19678  
    1717 
    1818public class MVRBTreePerfTest extends TestDbAbstract { 
     19        public static int MAP_SIZE = 20000; 
    1920 
    2021        protected FactorySequentialLong fFactorySeqLong = new FactorySequentialLong(); 
     
    2627        @Test 
    2728        public void test1() { 
    28                 int vSize = 200000; 
     29                int vSize = MAP_SIZE; 
    2930                fDatabase = fDbDriver.acquireDatabase(); 
    3031 
     
    3839                        vTree.put(vKey, fFactorySeqLong.newValueFor(vKey)); 
    3940                        vTree.lazySave(); 
    40                         Assert.assertEquals(i, vTree.size()); 
     41                        checkSize(vTree, i); 
    4142                } 
    42                 Assert.assertEquals(vSize, vTree.size()); 
     43                checkSize(vTree, vSize); 
    4344                checkAllEntries(vTree); 
    4445 
     
    4647                vTree = new OMVRBTreeDatabaseLazySave<Long, Long>(fDatabase, vId); 
    4748                vTree.load(); 
    48                 Assert.assertEquals(vSize, vTree.size()); 
     49                checkSize(vTree, vSize); 
    4950                checkAllEntries(vTree); 
     51 
     52                forceNewDatabase(); 
     53                vTree = new OMVRBTreeDatabaseLazySave<Long, Long>(fDatabase, vId); 
     54                vTree.load(); 
     55                for (Iterator<Long> vIt = fFactorySeqLong.unorderedIterator(); vIt.hasNext();) { 
     56                        Long vKey = vIt.next(); 
     57                        fFactorySeqLong.checkValueForKey(vKey, vTree.get(vKey)); 
     58                } 
     59 
     60                //Remove entries 
     61                forceNewDatabase(); 
     62                vTree = new OMVRBTreeDatabaseLazySave<Long, Long>(fDatabase, vId); 
     63                vTree.load(); 
     64                Long vKey = fFactorySeqLong.getUnorderedKeyToRemove(); 
     65                while (vKey != null) { 
     66                        //System.out.println(vKey); 
     67                        vTree.remove(vKey); 
     68                        vTree.lazySave(); 
     69                        //checkAllEntries(vTree); 
     70                        vKey = fFactorySeqLong.getUnorderedKeyToRemove(); 
     71                } 
     72                Assert.assertTrue(vTree.isEmpty()); 
     73        } 
     74 
     75        protected void checkSize(Map<Long, Long> pTree, int pSize) { 
     76                Assert.assertEquals(pTree.size(), pSize); 
    5077        } 
    5178 
     
    5683                        vCount++; 
    5784                } 
    58                 Assert.assertEquals(pTree.size(), vCount); 
     85                checkSize(pTree, vCount); 
    5986                for (Iterator<Long> vIt = fFactorySeqLong.creationOrderIterator(); vIt.hasNext();) { 
    6087                        Long vKey = vIt.next(); 
Note: See TracChangeset for help on using the changeset viewer.