Search in sources :

Example 6 with Entry

use of org.drools.core.util.Entry in project drools by kiegroup.

the class TupleIndexHashTable method toArray.

@Override
public Tuple[] toArray() {
    Tuple[] result = new Tuple[this.factSize];
    int index = 0;
    for (Entry aTable : this.table) {
        TupleList bucket = (TupleList) aTable;
        while (bucket != null) {
            Tuple entry = bucket.getFirst();
            while (entry != null) {
                result[index++] = entry;
                entry = entry.getNext();
            }
            bucket = bucket.getNext();
        }
    }
    return result;
}
Also used : Entry(org.drools.core.util.Entry) Tuple(org.drools.core.spi.Tuple)

Example 7 with Entry

use of org.drools.core.util.Entry in project drools by kiegroup.

the class TupleIndexRBTree method toArray.

public Entry[] toArray() {
    FastIterator it = tree.fastIterator();
    if (it == null) {
        return new Entry[0];
    }
    List<Comparable> toBeRemoved = new ArrayList<Comparable>();
    List<Tuple> result = new ArrayList<Tuple>();
    TupleList list = null;
    while ((list = (TupleList) it.next(list)) != null) {
        Tuple entry = list.getFirst();
        while (entry != null) {
            result.add(entry);
            entry = (Tuple) entry.getNext();
        }
    }
    return result.toArray(new Tuple[result.size()]);
}
Also used : Entry(org.drools.core.util.Entry) ArrayList(java.util.ArrayList) FastIterator(org.drools.core.util.FastIterator) Tuple(org.drools.core.spi.Tuple)

Example 8 with Entry

use of org.drools.core.util.Entry in project drools by kiegroup.

the class RightTupleIndexHashTableTest method getEntries.

private Entry[] getEntries(final AbstractHashTable map) throws Exception {
    final Field field = AbstractHashTable.class.getDeclaredField("table");
    field.setAccessible(true);
    final List list = new ArrayList();
    final Entry[] array = (Entry[]) field.get(map);
    for (int i = 0, length = array.length; i < length; i++) {
        if (array[i] != null) {
            list.add(array[i]);
        }
    }
    return (Entry[]) list.toArray(new Entry[list.size()]);
}
Also used : Field(java.lang.reflect.Field) Entry(org.drools.core.util.Entry) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) TupleList(org.drools.core.util.index.TupleList) List(java.util.List)

Example 9 with Entry

use of org.drools.core.util.Entry in project drools by kiegroup.

the class RightTupleIndexHashTableTest method testTwoDifferentEntriesSameHashCode.

@Test
public void testTwoDifferentEntriesSameHashCode() throws Exception {
    final InternalReadAccessor extractor = store.getReader(TestClass.class, "object");
    final Pattern pattern = new Pattern(0, new ClassObjectType(TestClass.class));
    final Declaration declaration = new Declaration("theObject", extractor, pattern);
    final FieldIndex fieldIndex = new FieldIndex(extractor, declaration);
    final TupleIndexHashTable map = new TupleIndexHashTable(new FieldIndex[] { fieldIndex }, false);
    final TestClass c1 = new TestClass(0, new TestClass(20, "stilton"));
    final InternalFactHandle ch1 = new DefaultFactHandle(1, c1);
    map.add(new RightTupleImpl(ch1, null));
    final TestClass c2 = new TestClass(0, new TestClass(20, "cheddar"));
    final InternalFactHandle ch2 = new DefaultFactHandle(2, c2);
    map.add(new RightTupleImpl(ch2, null));
    // same hashcode, but different values, so it should result in  a size of 2
    assertEquals(2, map.size());
    // however both are in the same table bucket
    assertEquals(1, tablePopulationSize(map));
    // this table bucket will have two FieldIndexEntries, as they are actually two different values
    Entry[] entries = getEntries(map);
    assertEquals(1, entries.length);
    TupleList list = (TupleList) entries[0];
    assertSame(ch2, list.getFirst().getFactHandle());
    assertNull(list.getFirst().getNext());
    assertSame(ch1, list.getNext().getFirst().getFactHandle());
    assertNull(list.getNext().getFirst().getNext());
    assertNull(list.getNext().getNext());
}
Also used : Pattern(org.drools.core.rule.Pattern) FieldIndex(org.drools.core.util.AbstractHashTable.FieldIndex) ClassObjectType(org.drools.core.base.ClassObjectType) RightTupleImpl(org.drools.core.reteoo.RightTupleImpl) TupleIndexHashTable(org.drools.core.util.index.TupleIndexHashTable) TupleList(org.drools.core.util.index.TupleList) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) Entry(org.drools.core.util.Entry) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) Declaration(org.drools.core.rule.Declaration) InternalFactHandle(org.drools.core.common.InternalFactHandle) Test(org.junit.Test)

Example 10 with Entry

use of org.drools.core.util.Entry in project drools by kiegroup.

the class BaseTupleIndexHashTableIteratorTest method createTableIndexListForAssertion.

protected List createTableIndexListForAssertion(TupleIndexHashTable hashTable) {
    Entry[] table = hashTable.getTable();
    List list = new ArrayList();
    for (int i = 0; i < table.length; i++) {
        if (table[i] != null) {
            List entries = new ArrayList();
            entries.add(i);
            Entry entry = table[i];
            while (entry != null) {
                entries.add(entry);
                entry = entry.getNext();
            }
            list.add(entries.toArray());
        }
    }
    return list;
}
Also used : Entry(org.drools.core.util.Entry) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BetaNodeFieldConstraint(org.drools.core.spi.BetaNodeFieldConstraint)

Aggregations

Entry (org.drools.core.util.Entry)12 ArrayList (java.util.ArrayList)5 TupleList (org.drools.core.util.index.TupleList)5 Tuple (org.drools.core.spi.Tuple)4 FastIterator (org.drools.core.util.FastIterator)4 Test (org.junit.Test)4 Field (java.lang.reflect.Field)3 List (java.util.List)2 ClassObjectType (org.drools.core.base.ClassObjectType)2 Declaration (org.drools.core.rule.Declaration)2 Pattern (org.drools.core.rule.Pattern)2 InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)2 AbstractHashTable (org.drools.core.util.AbstractHashTable)2 FieldIndex (org.drools.core.util.AbstractHashTable.FieldIndex)2 RBTree (org.drools.core.util.RBTree)2 TupleIndexHashTable (org.drools.core.util.index.TupleIndexHashTable)2 FieldIndexHashTableFullIterator (org.drools.core.util.index.TupleIndexHashTable.FieldIndexHashTableFullIterator)2 IOException (java.io.IOException)1 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)1 InternalFactHandle (org.drools.core.common.InternalFactHandle)1