use of org.drools.core.util.Entry in project drools by kiegroup.
the class MemoryVisitor method checkRightTupleIndexHashTable.
private void checkRightTupleIndexHashTable(final TupleIndexHashTable memory) {
final Entry[] entries = memory.getTable();
int factCount = 0;
int bucketCount = 0;
FastIterator it = LinkedList.fastIterator;
for (Entry entry1 : entries) {
if (entry1 != null) {
TupleList rightTupleList = (TupleList) entry1;
while (rightTupleList != null) {
if (rightTupleList.getFirst() != null) {
Entry entry = rightTupleList.getFirst();
while (entry != null) {
entry = it.next(entry);
factCount++;
}
} else {
logger.info("error : fieldIndexHashTable cannot have empty FieldIndexEntry objects");
}
rightTupleList = rightTupleList.getNext();
bucketCount++;
}
}
}
try {
final Field field = AbstractHashTable.class.getDeclaredField("size");
field.setAccessible(true);
logger.info(indent() + "FieldIndexBuckets: " + field.get(memory) + ":" + bucketCount);
if ((Integer) field.get(memory) != bucketCount) {
logger.info(indent() + "error");
}
} catch (final Exception e) {
e.printStackTrace();
}
logger.info(indent() + "FieldIndexFacts: " + memory.size() + ":" + factCount);
if (memory.size() != factCount) {
logger.info(indent() + "error");
}
}
use of org.drools.core.util.Entry in project drools by kiegroup.
the class LeftTupleIndexRangeRBTree method toArray.
public Entry[] toArray() {
FastIterator it = tree.fastIterator();
if (it == null) {
return new Entry[0];
}
List<Comparable> toBeRemoved = new ArrayList<Comparable>();
List<Comparable> nestedToBeRemoved = new ArrayList<Comparable>();
List<Tuple> result = new ArrayList<Tuple>();
RBTree.Node<Comparable<Comparable>, RBTree<Comparable<Comparable>, TupleList>> node = null;
RBTree.Node<Comparable<Comparable>, TupleList> nestedNode = null;
while ((node = (RBTree.Node<Comparable<Comparable>, RBTree<Comparable<Comparable>, TupleList>>) it.next(node)) != null) {
nestedToBeRemoved.clear();
RBTree<Comparable<Comparable>, TupleList> nestedTree = node.value;
FastIterator nestedIt = nestedTree.fastIterator();
while ((nestedNode = (RBTree.Node<Comparable<Comparable>, TupleList>) nestedIt.next(nestedNode)) != null) {
TupleList list = nestedNode.value;
int listSize = list.size();
if (listSize == 0) {
nestedToBeRemoved.add(nestedNode.key);
} else {
Tuple entry = list.getFirst();
while (entry != null) {
result.add(entry);
entry = (Tuple) entry.getNext();
}
}
}
for (Comparable key : nestedToBeRemoved) {
nestedTree.delete(key);
}
if (nestedTree.isEmpty()) {
toBeRemoved.add(node.key);
}
}
for (Comparable key : toBeRemoved) {
tree.delete(key);
}
return result.toArray(new Tuple[result.size()]);
}
use of org.drools.core.util.Entry in project drools by kiegroup.
the class RightTupleIndexRangeRBTree 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>();
RBTree.Node<Comparable<Comparable>, TupleList> node;
while ((node = (RBTree.Node<Comparable<Comparable>, TupleList>) it.next(null)) != null) {
TupleList bucket = node.value;
if (bucket.size() == 0) {
toBeRemoved.add(node.key);
} else {
Tuple entry = bucket.getFirst();
while (entry != null) {
result.add(entry);
entry = (Tuple) entry.getNext();
}
}
}
for (Comparable key : toBeRemoved) {
tree.delete(key);
}
return result.toArray(new Tuple[result.size()]);
}
use of org.drools.core.util.Entry in project drools by kiegroup.
the class RightTupleIndexHashTableTest method testResize.
@Test
public void testResize() throws Exception {
final InternalReadAccessor extractor = store.getReader(Cheese.class, "type");
final Pattern pattern = new Pattern(0, new ClassObjectType(Cheese.class));
final Declaration declaration = new Declaration("typeOfCheese", extractor, pattern);
final FieldIndex fieldIndex = new FieldIndex(extractor, declaration);
final TupleIndexHashTable map = new TupleIndexHashTable(16, 0.75f, new FieldIndex[] { fieldIndex }, false);
assertEquals(0, map.size());
final Cheese stilton1 = new Cheese("stilton", 35);
map.add(newRightTuple(1, stilton1));
final Cheese stilton2 = new Cheese("stilton", 81);
map.add(newRightTuple(2, stilton2));
final Cheese cheddar1 = new Cheese("cheddar", 35);
map.add(newRightTuple(3, cheddar1));
final Cheese cheddar2 = new Cheese("cheddar", 38);
map.add(newRightTuple(4, cheddar2));
final Cheese brie = new Cheese("brie", 293);
map.add(newRightTuple(5, brie));
final Cheese mozerella = new Cheese("mozerella", 15);
map.add(newRightTuple(6, mozerella));
final Cheese dolcelatte = new Cheese("dolcelatte", 284);
map.add(newRightTuple(7, dolcelatte));
final Cheese camembert1 = new Cheese("camembert", 924);
map.add(newRightTuple(8, camembert1));
final Cheese camembert2 = new Cheese("camembert", 765);
map.add(newRightTuple(9, camembert2));
final Cheese redLeicestor = new Cheese("red leicestor", 23);
map.add(newRightTuple(10, redLeicestor));
final Cheese wensleydale = new Cheese("wensleydale", 20);
map.add(newRightTuple(11, wensleydale));
final Cheese edam = new Cheese("edam", 12);
map.add(newRightTuple(12, edam));
final Cheese goude1 = new Cheese("goude", 93);
map.add(newRightTuple(13, goude1));
final Cheese goude2 = new Cheese("goude", 88);
map.add(newRightTuple(14, goude2));
final Cheese gruyere = new Cheese("gruyere", 82);
map.add(newRightTuple(15, gruyere));
final Cheese emmental = new Cheese("emmental", 98);
map.add(newRightTuple(16, emmental));
// At this point we have 16 facts but only 12 different types of cheeses
// so no table resize and thus its size is 16
assertEquals(16, map.size());
Entry[] table = map.getTable();
assertEquals(16, table.length);
final Cheese feta = new Cheese("feta", 48);
map.add(newRightTuple(2, feta));
// This adds our 13th type of cheese. The map is set with an initial capacity of 16 and
// a threshold of 75%, that after 12 it should resize the map to 32.
assertEquals(17, map.size());
table = map.getTable();
assertEquals(32, table.length);
final Cheese haloumi = new Cheese("haloumi", 48);
map.add(newRightTuple(2, haloumi));
final Cheese chevre = new Cheese("chevre", 48);
map.add(newRightTuple(2, chevre));
}
use of org.drools.core.util.Entry in project drools by kiegroup.
the class RightTupleIndexHashTableTest method tablePopulationSize.
private int tablePopulationSize(final AbstractHashTable map) throws Exception {
final Field field = AbstractHashTable.class.getDeclaredField("table");
field.setAccessible(true);
final Entry[] array = (Entry[]) field.get(map);
int size = 0;
for (int i = 0, length = array.length; i < length; i++) {
if (array[i] != null) {
size++;
}
}
return size;
}
Aggregations