public class ListBindingSet extends Object implements IBindingSet
An IBindingSet
based on a LinkedList
. Since Var
s may
be compared using ==
this should be faster than a hash map for
most operations unless the binding set has a large number of entries.
Note: #push()
and #pop(boolean)
are implemented by making a
copy of the current symbol table with distinct Map.Entry
objects. If
the symbol table is saved when it is #pop(boolean) popped), then it
simply replaces the pre-existing symbol table which was uncovered when it
was popped off of the stack. This design has several advantages, including:
null
values or
delete markers.Modifier | Constructor and Description |
---|---|
|
ListBindingSet()
Create an empty binding set.
|
|
ListBindingSet(IVariable[] vars,
IConstant[] vals)
Alternative constructor.
|
protected |
ListBindingSet(ListBindingSet src,
IVariable[] variablesToKeep)
Copy constructor (used by clone, copy).
|
Modifier and Type | Method and Description |
---|---|
void |
clear(IVariable var)
Clear any binding for the variable.
|
void |
clearAll()
Clear all bindings.
|
ListBindingSet |
clone()
Return a shallow copy of the binding set.
|
boolean |
containsErrorValues() |
IBindingSet |
copy(IVariable[] variablesToKeep)
Return a shallow copy of the binding set, eliminating unnecessary
variables.
|
IBindingSet |
copyMinusErrors(IVariable[] variablesToKeep)
Return a shallow copy of the binding set, eliminating unnecessary
variables and error values (equal to Constant.errorValueConstant()).
|
boolean |
equals(Object t)
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.
|
int |
hashCode()
The hash code of a binding is defined as the bit-wise XOR of the hash
codes of the
IConstant s for its bound variables. |
boolean |
isBound(IVariable var)
Return
true iff the variable is bound. |
boolean |
isEmpty()
true iff there are no variable bindings in the binding set. |
Iterator<Map.Entry<IVariable,IConstant>> |
iterator()
Visits the bindings.
|
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.
|
public ListBindingSet()
public ListBindingSet(IVariable[] vars, IConstant[] vals)
vars
- A copy is made of the data.vals
- A copy is made of the data.protected ListBindingSet(ListBindingSet src, IVariable[] variablesToKeep)
src
- The source to be copied.variablesToKeep
- The variables to be retained for the symbol table on the top
of the stack (optional).public ListBindingSet clone()
IBindingSet
clone
in interface IBindingSet
clone
in class Object
public IBindingSet copy(IVariable[] variablesToKeep)
IBindingSet
copy
in interface IBindingSet
variablesToKeep
- When non-null
, only the listed variables are
retained.public final IBindingSet copyMinusErrors(IVariable[] variablesToKeep)
IBindingSet
copyMinusErrors
in interface IBindingSet
variablesToKeep
- When non-null
, only the listed variables are
retained.public final boolean containsErrorValues()
containsErrorValues
in interface IBindingSet
public void clear(IVariable var)
IBindingSet
clear
in interface IBindingSet
var
- The variable.public void clearAll()
IBindingSet
clearAll
in interface IBindingSet
public IConstant get(IVariable var)
IBindingSet
get
in interface IBindingSet
var
- The variable.null
iff the
variable is not bound.public boolean isBound(IVariable var)
IBindingSet
true
iff the variable is bound.isBound
in interface IBindingSet
var
- The variable.true
if the variable is bound.public Iterator<Map.Entry<IVariable,IConstant>> iterator()
IBindingSet
iterator
in interface IBindingSet
public void set(IVariable var, IConstant val)
IBindingSet
set
in interface IBindingSet
var
- The variable.val
- The value (MAY NOT be null
).public boolean isEmpty()
IBindingSet
true
iff there are no variable bindings in the binding set.isEmpty
in interface IBindingSet
public int size()
IBindingSet
size
in interface IBindingSet
public Iterator<IVariable> vars()
IBindingSet
vars
in interface IBindingSet
public boolean equals(Object t)
IBindingSet
equals
in interface IBindingSet
equals
in class Object
t
- Another binding set.public int hashCode()
IBindingSet
IConstant
s for its bound variables. Unbound
variables are ignored when computing the hash code. Binding sets are
unordered collections, therefore the calculated hash code intentionally
does not depend on the order in which the bindings are visited. The hash
code reflects the current state of the bindings and must be recomputed if
the bindings are changed.hashCode
in interface IBindingSet
hashCode
in class Object
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.