Changeset 19674


Ignore:
Timestamp:
02/08/12 09:39:42 (4 months ago)
Author:
sys
Message:

Tree en cours...

Location:
trunk/Jav_Orient
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Jav_Orient/src/eu/scenari/orient/recordstruct/lib/base/StructList.java

    r19672 r19674  
    4949import eu.scenari.orient.recordstruct.struct.StructAbstract; 
    5050 
    51 public class StructList extends StructAbstract<ValueList> implements IStructList<ValueList> { 
     51public class StructList extends StructAbstract<ValueList<?>> implements IStructList<ValueList<?>> { 
    5252 
    5353        public StructList(int pCoreStructId) { 
  • trunk/Jav_Orient/src/eu/scenari/orient/recordstruct/value/ValueListImmutableFixed.java

    r19672 r19674  
    8686 
    8787                public E get(int pIndex) { 
     88                        assert (pIndex >= 0 && pIndex < fToIndex); 
    8889                        return ValueListImmutableFixed.this.get(fFromIndex + pIndex); 
    8990                } 
     
    105106 
    106107                public void add(int pIndex, E pElt) { 
     108                        assert (pIndex >= 0 && pIndex <= fToIndex); 
    107109                        fToIndex++; 
    108110                        ValueListImmutableFixed.this.add(fFromIndex + pIndex, pElt); 
     
    110112 
    111113                public boolean addAll(int pIndex, Collection<? extends E> pC) { 
     114                        assert (pIndex >= 0 && pIndex <= fToIndex); 
    112115                        fToIndex += pC.size(); 
    113116                        return ValueListImmutableFixed.this.addAll(fFromIndex + pIndex, pC); 
     
    115118 
    116119                public E set(int pIndex, E pElement) { 
     120                        assert (pIndex >= 0 && pIndex < fToIndex); 
    117121                        return ValueListImmutableFixed.this.set(fFromIndex + pIndex, pElement); 
    118122                } 
    119123 
    120124                public E remove(int pIndex) { 
     125                        assert (pIndex >= 0 && pIndex < fToIndex); 
    121126                        fToIndex--; 
    122127                        return ValueListImmutableFixed.this.remove(fFromIndex + pIndex); 
  • trunk/Jav_Orient/src/eu/scenari/orient/tree/impl/Tree.java

    r19672 r19674  
    228228 
    229229        public V get(Object pKey) { 
    230                 return fRoot.findSlot(pKey).get(pKey); 
     230                TreeSlot<K, V> vSlot = fRoot.findSlot(pKey); 
     231                return vSlot != null ? vSlot.get(pKey) : null; 
    231232        } 
    232233 
    233234        public boolean containsKey(Object pKey) { 
    234                 return fRoot.findSlot(pKey).indexOf(pKey) >= 0; 
     235                TreeSlot<K, V> vSlot = fRoot.findSlot(pKey); 
     236                return vSlot != null ? vSlot.indexOf(pKey) >= 0 : false; 
    235237        } 
    236238 
    237239        public V put(K pKey, V pValue) { 
    238240                TreeSlot<K, V> vSlot = fRoot.findSlot(pKey); 
     241                if (vSlot == null) vSlot = fRoot.findFirstSlot(); 
    239242                ITreeSlotProvider<K, V> vSlotProvider = vSlot.getProvider(); 
    240243                int vCurrentOffset = vSlot.indexOf(pKey); 
     
    259262        public V remove(Object pKey) { 
    260263                TreeSlot<K, V> vSlot = fRoot.findSlot(pKey); 
     264                if (vSlot == null) return null; 
    261265                int vOffset = vSlot.indexOf(pKey); 
    262266                if (vOffset < 0) return null; 
  • trunk/Jav_Orient/src/eu/scenari/orient/tree/impl/TreeNode.java

    r19672 r19674  
    4343 
    4444        public K getKey(int pOffset) { 
    45                 return fProvider.getKey(0); 
     45                return fProvider.getKey(pOffset); 
    4646        } 
    4747 
  • trunk/Jav_Orient/src/eu/scenari/orient/tree/impl/TreeRake.java

    r19672 r19674  
    187187 
    188188        public TreeSlot<K, V> findSlot(Object pKey) { 
     189                int vLast = -1; 
    189190                int vLow = 0; 
    190191                int vHigh = fProvider.getSize() - 1; 
    191                 while (vLow < vHigh) { 
     192                while (vLow <= vHigh) { 
    192193                        int vMid = (vLow + vHigh) >>> 1; 
    193194                        K vMidKey = getKey(vMid); 
    194195                        int vCmp = fTree.fComparator.compare(vMidKey, (K) pKey); 
    195196                        if (vCmp < 0) { 
     197                                vLast = vMid; 
    196198                                vLow = vMid + 1; 
    197199                        } else if (vCmp > 0) { 
     
    202204                        } 
    203205                } 
    204                 return getNode(vLow).findSlot(pKey); 
     206                return vLast >= 0 ? getNode(vLast).findSlot(pKey) : null; 
    205207        } 
    206208 
  • trunk/Jav_Orient/test/eu/scenari/orient/tree/FactorySequentialLong.java

    r19672 r19674  
    1111public class FactorySequentialLong implements IKeyFactory<Long>, IValueFactory<Long> { 
    1212 
     13        protected long fStartValue = 1; 
     14 
    1315        protected Random fRandom = new Random(); 
    1416 
    15         protected AtomicLong fCounter = new AtomicLong(1); 
     17        protected AtomicLong fCounter = new AtomicLong(fStartValue); 
    1618 
    1719        public Long newKey() { 
     
    2931        public Iterator<Long> creationOrderIterator() { 
    3032                return new IteratorBufferedNextBase<Long>() { 
    31                         protected long fLast = 1; 
     33                        protected long fLast = fStartValue; 
    3234 
    3335                        public boolean hasNext() { 
     
    3537                                if (fNext != null) return true; 
    3638                                //Cherche à renseigner fNext 
    37                                 if (fLast <= fCounter.get()) { 
     39                                if (fLast < fCounter.get()) { 
    3840                                        fNext = fLast++; 
    3941                                } 
  • trunk/Jav_Orient/test/eu/scenari/orient/tree/TreeBasicTest.java

    r19672 r19674  
    3939package eu.scenari.orient.tree; 
    4040 
     41import java.util.Iterator; 
    4142import java.util.Map; 
    4243 
     
    5455import eu.scenari.orient.recordstruct.types.TypesBase; 
    5556import eu.scenari.orient.test.TestDbAbstract; 
     57import eu.scenari.orient.tree.impl.IBalancingLayout; 
    5658 
    5759public class TreeBasicTest extends TestDbAbstract { 
    5860 
    59         public static final TreeStorageConfig TREECONFIG = new TreeStorageConfig().setKeysStruct(TypesBase.LIST_LONG).setValuesStruct(TypesBase.LIST_LONG); 
     61        public static final TreeStorageConfig TREECONFIG = new TreeStorageConfig().setKeysStruct(TypesBase.LIST_LONG).setValuesStruct(TypesBase.LIST_LONG).setSizeStored(false).setBalancingLayout(IBalancingLayout.DEFAULT_BALANCED_INCREMENTAL_INSERT); 
    6062 
    6163        public static final StructTree TREE_LONG_LONG = new StructTree(new ExtendedStructId(1, 1), "trreeLongLong").setTreeConfig(TREECONFIG); 
    6264 
    63         protected FactorySequentialLong fFactory = new FactorySequentialLong(); 
     65        protected FactorySequentialLong fFactorySeqLong = new FactorySequentialLong(); 
    6466 
    6567        @Override 
     
    7880                Map<Long, Long> vTree = vRecord.getValue().getPojo(); 
    7981                for (int i = 1; i <= vSize; i++) { 
    80                         Long vKey = fFactory.newKey(); 
    81                         vTree.put(vKey, fFactory.newValueFor(vKey)); 
     82                        Long vKey = fFactorySeqLong.newKey(); 
     83                        vTree.put(vKey, fFactorySeqLong.newValueFor(vKey)); 
    8284                        vRecord.save(); 
    8385                        Assert.assertEquals(i, vTree.size()); 
     
    9193                Assert.assertEquals(vSize, vTree.size()); 
    9294                checkAllEntries(vTree); 
     95 
    9396        } 
    9497 
     
    9699                int vCount = 0; 
    97100                for (Map.Entry<Long, Long> vEntry : pTree.entrySet()) { 
    98                         fFactory.checkValueForKey(vEntry.getKey(), vEntry.getValue()); 
     101                        fFactorySeqLong.checkValueForKey(vEntry.getKey(), vEntry.getValue()); 
    99102                        vCount++; 
    100103                } 
    101104                Assert.assertEquals(pTree.size(), vCount); 
     105                for (Iterator<Long> vIt = fFactorySeqLong.creationOrderIterator(); vIt.hasNext();) { 
     106                        Long vKey = vIt.next(); 
     107                        fFactorySeqLong.checkValueForKey(vKey, pTree.get(vKey)); 
     108                } 
     109 
    102110        } 
    103111 
Note: See TracChangeset for help on using the changeset viewer.