com.bigdata.relation.rule
Class ArrayBindingSet

java.lang.Object
  extended by com.bigdata.relation.rule.ArrayBindingSet
All Implemented Interfaces:
IBindingSet, Serializable, Cloneable

public class ArrayBindingSet
extends Object
implements IBindingSet

An IBindingSet backed by an dense array (no gaps). This implementation is more efficient for fixed or small N (N LTE ~20). It simples scans the array looking for the variable using references tests for equality. Since the #of variables is generally known in advance this can be faster and lighter than HashBindingSet for most applications.

Version:
$Id: ArrayBindingSet.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson
See Also:
Serialized Form

Field Summary
protected static boolean DEBUG
          True iff the log level is DEBUG or less.
protected static boolean INFO
          True iff the log level is INFO or less.
protected static org.apache.log4j.Logger log
           
 
Constructor Summary
protected ArrayBindingSet(ArrayBindingSet bindingSet)
          Copy constructor.
  ArrayBindingSet(int capacity)
          Initialized with the given capacity.
  ArrayBindingSet(IVariable[] vars, IConstant[] vals)
          Initialized with the given bindings (assumes for efficiency that all elements of bound arrays are non-null and that no variables are duplicated).
 
Method Summary
 void clear(IVariable var)
          Since the array is dense (no gaps), clear(IVariable) requires that we copy down any remaining elements in the array by one position.
 void clearAll()
          Clear all bindings.
 ArrayBindingSet clone()
          Return a shallow copy of the binding set.
 boolean equals(IBindingSet o)
          True iff the variables and their bound values are the same for the two binding sets.
 IConstant get(IVariable var)
          Return the binding for the variable.
 boolean isBound(IVariable var)
          Return true iff the variable is bound.
 Iterator<Map.Entry<IVariable,IConstant>> iterator()
          Iterator does not support either removal or concurrent modification of the binding set.
 void set(IVariable var, IConstant val)
          Bind the variable to the value.
 int size()
          The #of bound variables.
 String toString()
           
 Iterator<IVariable> vars()
          Visits the bound variables.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected static final org.apache.log4j.Logger log

INFO

protected static final boolean INFO
True iff the log level is INFO or less.


DEBUG

protected static final boolean DEBUG
True iff the log level is DEBUG or less.

Constructor Detail

ArrayBindingSet

protected ArrayBindingSet(ArrayBindingSet bindingSet)
Copy constructor.


ArrayBindingSet

public ArrayBindingSet(IVariable[] vars,
                       IConstant[] vals)
Initialized with the given bindings (assumes for efficiency that all elements of bound arrays are non-null and that no variables are duplicated).

Parameters:
vars - The variables.
vals - Their bound values.

ArrayBindingSet

public ArrayBindingSet(int capacity)
Initialized with the given capacity.

Parameters:
capacity - The capacity.
Throws:
IllegalArgumentException - if the capacity is negative.
Method Detail

vars

public Iterator<IVariable> vars()
Description copied from interface: IBindingSet
Visits the bound variables.

Specified by:
vars in interface IBindingSet

iterator

public Iterator<Map.Entry<IVariable,IConstant>> iterator()
Iterator does not support either removal or concurrent modification of the binding set.

Specified by:
iterator in interface IBindingSet

size

public int size()
Description copied from interface: IBindingSet
The #of bound variables.

Specified by:
size in interface IBindingSet

clearAll

public void clearAll()
Description copied from interface: IBindingSet
Clear all bindings.

Specified by:
clearAll in interface IBindingSet

clear

public void clear(IVariable var)
Since the array is dense (no gaps), clear(IVariable) requires that we copy down any remaining elements in the array by one position.

Specified by:
clear in interface IBindingSet
Parameters:
var - The variable.

get

public IConstant get(IVariable var)
Description copied from interface: IBindingSet
Return the binding for the variable.

Specified by:
get in interface IBindingSet
Parameters:
var - The variable.
Returns:
the binding for the variable -or- null iff the variable is not bound.

isBound

public boolean isBound(IVariable var)
Description copied from interface: IBindingSet
Return true iff the variable is bound.

Specified by:
isBound in interface IBindingSet
Parameters:
var - The variable.
Returns:
true if the variable is bound.

set

public void set(IVariable var,
                IConstant val)
Description copied from interface: IBindingSet
Bind the variable to the value.

Specified by:
set in interface IBindingSet
Parameters:
var - The variable.
val - The value (MAY NOT be null).

toString

public String toString()
Overrides:
toString in class Object

clone

public ArrayBindingSet clone()
Description copied from interface: IBindingSet
Return a shallow copy of the binding set.

Specified by:
clone in interface IBindingSet
Overrides:
clone in class Object

equals

public boolean equals(IBindingSet o)
Description copied from interface: IBindingSet
True iff the variables and their bound values are the same for the two binding sets.

Specified by:
equals in interface IBindingSet
Parameters:
o - Another binding set.


Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.