/*
 * Copyright (c) 2012 Mateusz Parzonka, Eric Bodden
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Mateusz Parzonka - initial API and implementation
 */
package prm4j.indexing.treebased.impl;

import prm4j.indexing.AbstractBaseMonitor;
import prm4j.indexing.Event;
import prm4j.indexing.IndexingStrategy;
import prm4j.indexing.treebased.BindingStore;
import prm4j.indexing.treebased.LowLevelBinding;
import prm4j.indexing.treebased.Node;
import prm4j.indexing.treebased.NodeStore;

public class FastIndexingStrategy<A> implements IndexingStrategy<A> {

    private BindingStore<A> bindingStore;
    private NodeStore<A> nodeStore;

    @Override
    public void processEvent(Event<A> event) {

	final LowLevelBinding<A>[] bindings = bindingStore.getBindings(event.getBoundObjects());
	final Node<A> instanceNode = nodeStore.getNode(bindings);
	final AbstractBaseMonitor<A> instanceMonitor = instanceNode.getMonitor();

	if (instanceMonitor == null) {
	    // TODO join and chain with implicit update
	} else {
	    // TODO just update
	}

    }

}

@@ -654,55 +654,169 @@
 sed.
-Node;%0Aimport prm4j.indexing.treebased.NodeStore
+MonitorSetIterator;%0Aimport prm4j.indexing.treebased.Node;%0Aimport prm4j.indexing.treebased.NodeStore;%0Aimport prm4j.logic.EventContext;%0Aimport prm4j.logic.JoinData
 ;%0A%0Ap
@@ -962,16 +962,55 @@
 deStore;
+%0A    private EventContext eventContext;
 %0A%0A    @O
@@ -1376,45 +1376,1960 @@
 te%0A%09
-%7D else %7B%0A%09    // TODO just update%0A%09%7D%0A
+    for (JoinData joinData : eventContext.getJoinData(event)) %7B%0A%09%09final Node%3CA%3E compatibleNode = nodeStore.getNode(bindings, joinData.getTraversalMask());%0A%09%09// calculate once the bindings to be joined with the whole monitor set%0A%09%09final LowLevelBinding%3CA%3E%5B%5D joinableBindings = getJoinableBindings(bindings,%0A%09%09%09joinData.getJoinTargetPattern());%0A%0A%09%09for (int parameterSetId : joinData.getParameterSetIds()) %7B%0A%09%09    // iterate over all compatible nodes%0A%09%09    MonitorSetIterator%3CA%3E iter = compatibleNode.getMonitorSet(parameterSetId).getIterator();%0A%09%09    AbstractBaseMonitor%3CA%3E compatibleMonitor = null;%0A%09%09    boolean isCompatibleMonitorAlive = false;%0A%09%09    while (iter.hasNext(compatibleMonitor, isCompatibleMonitorAlive)) %7B%0A%09%09%09compatibleMonitor = iter.next();%0A%09%09%09isCompatibleMonitorAlive = expand(compatibleMonitor, joinableBindings,%0A%09%09%09%09joinData.getJoinSourcePattern(), joinData.getDisableMask(), event);%0A%09%09    %7D%0A%09%09%7D%0A%09    %7D%0A%0A%09%7D else %7B%0A%09    // TODO just update%0A%09%7D%0A%0A    %7D%0A%0A    /**%0A     * Returns an array of bindings containing %22gaps%22 enabling efficient joins by filling these gaps.%0A     *%0A     * @param binding%0A     * @param joinTargetPattern%0A     *            allows transformation of the binding to a joinable binding%0A     * @return a joinable binding%0A     */%0A    static %3CA%3E LowLevelBinding%3CA%3E%5B%5D getJoinableBindings(LowLevelBinding%3CA%3E%5B%5D binding, int%5B%5D joinTargetPattern) %7B%0A%09@SuppressWarnings(%22unchecked%22)%0A%09final LowLevelBinding%3CA%3E%5B%5D result = new LowLevelBinding%5BjoinTargetPattern.length%5D;%0A%09for (int i = 0; i %3C joinTargetPattern.length; i++) %7B%0A%09    final int destination = joinTargetPattern%5Bi%5D;%0A%09    if (destination %3E= 0) // pointers to -1 encode null in the result%0A%09%09result%5Bi%5D = binding%5Bdestination%5D;%0A%09%7D%0A%09return result;%0A    %7D%0A%0A    protected boolean expand(AbstractBaseMonitor%3CA%3E compatibleMonitor, LowLevelBinding%3CA%3E%5B%5D joinableBindings,%0A%09    int%5B%5D joinSourcePattern, int%5B%5D disableMask, Event%3CA%3E event) %7B%0A%09// TODO Auto-generated method stub%0A%09return false;
 %0A   

Use JoinData in FastIndexingStrategy