public class HashBindingSet extends Object implements IBindingSet
IBindingSet
backed by a LinkedHashMap
.
Note: A LinkedHashMap
provides a fast iterator, which we use a bunch.
However, IBindingSet
s are inherently unordered collections of
bindings so the order preservation aspect of the LinkedHashMap
is not
relied upon.
Modifier | Constructor and Description |
---|---|
|
HashBindingSet()
New empty binding set.
|
protected |
HashBindingSet(HashBindingSet 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.
|
HashBindingSet |
clone()
Return a shallow copy of the binding set.
|
boolean |
containsErrorValues() |
HashBindingSet |
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 HashBindingSet()
protected HashBindingSet(HashBindingSet src, IVariable[] variablesToKeep)
src
- public HashBindingSet clone()
IBindingSet
clone
in interface IBindingSet
clone
in class Object
public HashBindingSet copy(IVariable[] variablesToKeep)
IBindingSet
copy
in interface IBindingSet
variablesToKeep
- When non-null
, only the listed variables are
retained.public 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 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 IConstant get(IVariable var)
IBindingSet
get
in interface IBindingSet
var
- The variable.null
iff the
variable is not bound.public void set(IVariable var, IConstant val)
IBindingSet
set
in interface IBindingSet
var
- The variable.val
- The value (MAY NOT be null
).public void clear(IVariable var)
IBindingSet
clear
in interface IBindingSet
var
- The variable.public void clearAll()
IBindingSet
clearAll
in interface IBindingSet
public Iterator<Map.Entry<IVariable,IConstant>> iterator()
IBindingSet
iterator
in interface IBindingSet
public Iterator<IVariable> vars()
IBindingSet
vars
in interface IBindingSet
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 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.