<commit_before>/*
 * Copyright (c) 2012 <NAME>, <NAME>
 * 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:
 * <NAME> - initial API and implementation
 */
package prm4j.indexing.treebased.impl;

import prm4j.indexing.Binding;
import prm4j.indexing.treebased.Instance;
import prm4j.indexing.treebased.LowLevelBinding;
import prm4j.indexing.treebased.Node;

/**
 * @param <A>
 *            the type of the auxiliary data usable by base monitors
 */
public class DefaultInstance<A> implements Instance<A> {

    private Node<A> rootNode;
    private LowLevelBinding<A>[] bindings;

    @Override
    public Binding[] getBindings() {
	// TODO Auto-generated method stub
	return null;
    }

    @Override
    public Node<A> getNode() {
	// fast track for the parameterless instance
	if (bindings.length == 0) {
	    return rootNode;
	}
	// retrieve the head of the array pointing to the first node we will use
	Node<A> node = bindings[0].getBaseNode();
	// we iterate over the rest { node1 , ..., nodeN }, traversing the tree
	for (int i = 1; i < bindings.length; i++) {
	    // traverse the node tree until the parameter instance is fully realized
	    node = node.getNodeMap().getNode(bindings[i]);
	}
	return node;
    }

    @Override
    public Node<A> getNode(int[] parameterMask) {
	// fast track for the parameterless instance
	if (parameterMask.length == 0) {
	    return rootNode;
	}
	// retrieve the head of the array pointing to the first node we will use
	Node<A> node = bindings[parameterMask[0]].getBaseNode();
	// we iterate over the rest { node1 , ..., nodeN }, traversing the tree
	for (int i = 1; i < parameterMask.length; i++) {
	    // traverse the node tree until the parameter instance is fully realized
	    node = node.getNodeMap().getNode(bindings[parameterMask[i]]);
	}
	return node;
    }

}
<commit_msg>Let Instance cache its Node<commit_after>/*
 * Copyright (c) 2012 <NAME>, <NAME>
 * 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:
 * <NAME> - initial API and implementation
 */
package prm4j.indexing.treebased.impl;

import prm4j.indexing.Binding;
import prm4j.indexing.treebased.Instance;
import prm4j.indexing.treebased.LowLevelBinding;
import prm4j.indexing.treebased.Node;

/**
 * @param <A>
 *            the type of the auxiliary data usable by base monitors
 */
public class DefaultInstance<A> implements Instance<A> {

    private Node<A> rootNode;
    private Node<A> cachedInstanceNode;
    private LowLevelBinding<A>[] bindings;

    @Override
    public Binding[] getBindings() {
	// TODO Auto-generated method stub
	return null;
    }

    @Override
    public Node<A> getNode() {
	// retrieve from cache
	if (cachedInstanceNode != null) {
	    return cachedInstanceNode;
	}
	// fast track for the parameterless instance
	if (bindings.length == 0) {
	    return rootNode;
	}
	// retrieve the head of the array pointing to the first node we will use
	Node<A> node = bindings[0].getBaseNode();
	// we iterate over the rest { node1 , ..., nodeN }, traversing the tree
	for (int i = 1; i < bindings.length; i++) {
	    // traverse the node tree until the parameter instance is fully realized
	    node = node.getNodeMap().getNode(bindings[i]);
	}
	cachedInstanceNode = node;
	return node;
    }

    @Override
    public Node<A> getNode(int[] parameterMask) {
	// fast track for the parameterless instance
	if (parameterMask.length == 0) {
	    return rootNode;
	}
	// retrieve the head of the array pointing to the first node we will use
	Node<A> node = bindings[parameterMask[0]].getBaseNode();
	// we iterate over the rest { node1 , ..., nodeN }, traversing the tree
	for (int i = 1; i < parameterMask.length; i++) {
	    // traverse the node tree until the parameter instance is fully realized
	    node = node.getNodeMap().getNode(bindings[parameterMask[i]]);
	}
	return node;
    }

}

{'fraction_non_alphanumeric': 0.10756223579145138, 'fraction_numerical': 0.00986378581493659, 'mean_word_length': 3.455020920502092, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2403889', 'n_tokens_mistral': 1324, 'n_tokens_neox': 1263, 'n_words': 445}