BetaConstraints betaConstraints = null;
betaConstraints = new SingleBetaConstraints( constraints,
config );
BetaMemory betaMemory = betaConstraints.createBetaMemory( config, NodeTypeEnums.JoinNode );
RuleBase rb = RuleBaseFactory.newRuleBase();
StatefulSession ss = rb.newStatefulSession();
InternalFactHandle fh1 = (InternalFactHandle) ss.insert( new Foo( "brie",
1 ) );
InternalFactHandle fh2 = (InternalFactHandle) ss.insert( new Foo( "brie",
1 ) );
InternalFactHandle fh3 = (InternalFactHandle) ss.insert( new Foo( "soda",
1 ) );
InternalFactHandle fh4 = (InternalFactHandle) ss.insert( new Foo( "soda",
1 ) );
InternalFactHandle fh5 = (InternalFactHandle) ss.insert( new Foo( "bread",
3 ) );
InternalFactHandle fh6 = (InternalFactHandle) ss.insert( new Foo( "bread",
3 ) );
InternalFactHandle fh7 = (InternalFactHandle) ss.insert( new Foo( "cream",
3 ) );
InternalFactHandle fh8 = (InternalFactHandle) ss.insert( new Foo( "gorda",
15 ) );
InternalFactHandle fh9 = (InternalFactHandle) ss.insert( new Foo( "beer",
16 ) );
InternalFactHandle fh10 = (InternalFactHandle) ss.insert( new Foo( "mars",
0 ) );
InternalFactHandle fh11 = (InternalFactHandle) ss.insert( new Foo( "snicker",
0 ) );
InternalFactHandle fh12 = (InternalFactHandle) ss.insert( new Foo( "snicker",
0 ) );
InternalFactHandle fh13 = (InternalFactHandle) ss.insert( new Foo( "snicker",
0 ) );
betaMemory.getLeftTupleMemory().add( new LeftTupleImpl( fh1,
null,
true ) );
betaMemory.getLeftTupleMemory().add( new LeftTupleImpl( fh2,
null,
true ) );
betaMemory.getLeftTupleMemory().add( new LeftTupleImpl( fh3,
null,
true ) );
betaMemory.getLeftTupleMemory().add( new LeftTupleImpl( fh4,
null,
true ) );
betaMemory.getLeftTupleMemory().add( new LeftTupleImpl( fh5,
null,
true ) );
betaMemory.getLeftTupleMemory().add( new LeftTupleImpl( fh6,
null,
true ) );
betaMemory.getLeftTupleMemory().add( new LeftTupleImpl( fh7,
null,
true ) );
betaMemory.getLeftTupleMemory().add( new LeftTupleImpl( fh8,
null,
true ) );
betaMemory.getLeftTupleMemory().add( new LeftTupleImpl( fh9,
null,
true ) );
LeftTupleIndexHashTable hashTable = (LeftTupleIndexHashTable) betaMemory.getLeftTupleMemory();
// can't create a 0 hashCode, so forcing
LeftTupleList leftTupleList = new LeftTupleList();
leftTupleList.add( new LeftTupleImpl( fh10,
null,
true ) );
hashTable.getTable()[0] = leftTupleList;
leftTupleList = new LeftTupleList();
leftTupleList.add( new LeftTupleImpl( fh11,
null,
true ) );
leftTupleList.add( new LeftTupleImpl( fh12,
null,
true ) );
leftTupleList.add( new LeftTupleImpl( fh13,
null,
true ) );
((LeftTupleList) hashTable.getTable()[0]).setNext( leftTupleList );
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() );
}
}
assertEquals( 5,
list.size() );
// This tests the hashcode index allocation. If the rehash function (or any other way hashcodes are computed) changes, these numbers will change.
Object[] entries = (Object[]) list.get( 0 );
assertEquals( 0,
entries[0] );
assertEquals( 3,
entries.length );
entries = (Object[]) list.get( 1 );
assertEquals( 102,
entries[0] );
assertEquals( 2,
entries.length );
entries = (Object[]) list.get( 2 );
assertEquals( 103,
entries[0] );
assertEquals( 2,
entries.length );
entries = (Object[]) list.get( 3 );
assertEquals( 115,
entries[0] );
assertEquals( 3,
entries.length );
entries = (Object[]) list.get( 4 );
assertEquals( 117,
entries[0] );
assertEquals( 3,
entries.length );
//System.out.println( entries );
list = new ArrayList<LeftTupleImpl>();
Iterator it = betaMemory.getLeftTupleMemory().iterator();
for ( LeftTupleImpl leftTuple = (LeftTupleImpl) it.next(); leftTuple != null; leftTuple = (LeftTupleImpl) it.next() ) {
list.add( leftTuple );
}
assertEquals( 13,