net.sf.bddbddb
Class Relation

java.lang.Object
  extended by net.sf.bddbddb.Relation
Direct Known Subclasses:
BDDRelation, LSRelation

public abstract class Relation
extends java.lang.Object

Represents a relation in bddbddb.

Version:
$Id: Relation.java 607 2005-07-15 00:04:10Z joewhaley $
Author:
jwhaley

Field Summary
protected  java.util.List attributes
          Attributes of this relation.
 int id
          Unique id number for this relation.
protected  java.lang.String name
          Name of this relation.
protected  Relation negated
          Negated form of this relation, or null if it doesn't exist.
 
Constructor Summary
protected Relation(Solver solver, java.lang.String name, java.util.List attributes)
          Create a new Relation.
 
Method Summary
abstract  boolean add(java.math.BigInteger[] tuple)
          Adds the given tuple to this relation.
abstract  boolean contains(int k, java.math.BigInteger j)
          Returns true iff this relation contains a tuple where the kth field is value j.
abstract  Relation copy()
          Make a copy of this relation.
abstract  double dsize()
          Return the number of tuples in this relation, in double format.
 java.lang.String elementsToString()
           
abstract  void free()
          Free the memory associated with this relation.
static Relation fromXMLElement(org.jdom.Element e, XMLFactory f)
           
 java.util.Map getAttribNameMap()
           
 Attribute getAttribute(int x)
          Get the attribute at the given index.
 Attribute getAttribute(java.lang.String x)
          Get the attribute with the given name.
 java.util.List getAttributes()
          Returns the list of attributes of this relation.
 PartialOrder.Constraints getConstraints()
          Returns the constraints.
 Relation getNegated()
          Return the negated form of this relation, or null if it does not exist.
 int hashCode()
          The hashCode for relations is deterministic.
abstract  void initialize()
          Initialize this relation.
abstract  TupleIterator iterator()
          Return an iterator over the tuples of this relation.
abstract  TupleIterator iterator(java.math.BigInteger[] j)
          Return an iterator over the tuples where the fields match the values in the given array.
abstract  TupleIterator iterator(int k)
          Return an iterator over the values in the kth field of the relation.
abstract  TupleIterator iterator(int k, java.math.BigInteger j)
          Return an iterator over the tuples where the kth field has value j.
abstract  void load()
          Load this relation from disk in its native format.
abstract  void loadTuples()
          Load the tuple form of this relation from disk.
abstract  void loadTuples(java.lang.String filename)
          Load this relation in tuple form from the given file.
 Relation makeNegated(Solver solver)
          Get or create the negated form of this relation.
 int numberOfAttributes()
          Returns the number of attributes.
abstract  void save()
          Save the current value of this relation to disk in its native format.
abstract  void saveTuples()
          Save the current value of this relation to disk in tuple form.
abstract  void saveTuples(java.lang.String filename)
          Save the value of this relation in tuple form to the given file.
 void setConstraints(PartialOrder.Constraints constraints)
          Set the constraints for this relation.
 long size()
          Return the number of tuples in this relation.
 java.lang.String toString()
           
 org.jdom.Element toXMLElement()
           
abstract  java.lang.String verboseToString()
          Returns a verbose representation of the relation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
Name of this relation.


attributes

protected java.util.List attributes
Attributes of this relation.


negated

protected Relation negated
Negated form of this relation, or null if it doesn't exist.


id

public final int id
Unique id number for this relation.

Constructor Detail

Relation

protected Relation(Solver solver,
                   java.lang.String name,
                   java.util.List attributes)
Create a new Relation.

Parameters:
solver - solver
name - name of relation
attributes - attributes for relation
Method Detail

initialize

public abstract void initialize()
Initialize this relation.


load

public abstract void load()
                   throws java.io.IOException
Load this relation from disk in its native format.

Throws:
java.io.IOException

loadTuples

public abstract void loadTuples()
                         throws java.io.IOException
Load the tuple form of this relation from disk.

Throws:
java.io.IOException

loadTuples

public abstract void loadTuples(java.lang.String filename)
                         throws java.io.IOException
Load this relation in tuple form from the given file.

Parameters:
filename - the file to load
Throws:
java.io.IOException

save

public abstract void save()
                   throws java.io.IOException
Save the current value of this relation to disk in its native format.

Throws:
java.io.IOException

saveTuples

public abstract void saveTuples()
                         throws java.io.IOException
Save the current value of this relation to disk in tuple form.

Throws:
java.io.IOException

saveTuples

public abstract void saveTuples(java.lang.String filename)
                         throws java.io.IOException
Save the value of this relation in tuple form to the given file.

Parameters:
filename - name of file to save
Throws:
java.io.IOException

copy

public abstract Relation copy()
Make a copy of this relation. The new relation will have the same attributes and a derived name.

Returns:
the new relation

free

public abstract void free()
Free the memory associated with this relation. After calling this, the relation can no longer be used.


size

public long size()
Return the number of tuples in this relation.

Returns:
number of tuples in relation

dsize

public abstract double dsize()
Return the number of tuples in this relation, in double format.

Returns:
number of tuples in relation

iterator

public abstract TupleIterator iterator()
Return an iterator over the tuples of this relation.

Returns:
iterator of BigInteger[]

iterator

public abstract TupleIterator iterator(int k)
Return an iterator over the values in the kth field of the relation. k is zero-based.

Parameters:
k - zero-based field number
Returns:
iterator of BigInteger[]

iterator

public abstract TupleIterator iterator(int k,
                                       java.math.BigInteger j)
Return an iterator over the tuples where the kth field has value j. k is zero-based.

Parameters:
k - zero-based field number
j - value
Returns:
iterator of BigInteger[]

iterator

public abstract TupleIterator iterator(java.math.BigInteger[] j)
Return an iterator over the tuples where the fields match the values in the given array. A -1 value in the array matches any value.

Parameters:
j - values
Returns:
iterator of BigInteger[]

contains

public abstract boolean contains(int k,
                                 java.math.BigInteger j)
Returns true iff this relation contains a tuple where the kth field is value j. k is zero-based.

Parameters:
k - zero-based field number
j - value
Returns:
whether the given value appears in the given field

add

public abstract boolean add(java.math.BigInteger[] tuple)
Adds the given tuple to this relation. Returns true if the relation changed.

Parameters:
tuple - new tuple
Returns:
true iff relation changed

getNegated

public Relation getNegated()
Return the negated form of this relation, or null if it does not exist.

Returns:
negated version of this relation, or null

makeNegated

public Relation makeNegated(Solver solver)
Get or create the negated form of this relation.

Parameters:
solver - solver
Returns:
negated version of this relation

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

verboseToString

public abstract java.lang.String verboseToString()
Returns a verbose representation of the relation


elementsToString

public java.lang.String elementsToString()

getAttributes

public java.util.List getAttributes()
Returns the list of attributes of this relation.

Returns:
attributes

getAttribute

public Attribute getAttribute(int x)
Get the attribute at the given index.

Parameters:
x - index
Returns:
attribute

getAttribute

public Attribute getAttribute(java.lang.String x)
Get the attribute with the given name.

Parameters:
x - name
Returns:
attribute

numberOfAttributes

public int numberOfAttributes()
Returns the number of attributes.

Returns:
number of attributes

getConstraints

public PartialOrder.Constraints getConstraints()
Returns the constraints.

Returns:
constraints

setConstraints

public void setConstraints(PartialOrder.Constraints constraints)
Set the constraints for this relation.

Parameters:
constraints - The constraints to set.

hashCode

public int hashCode()
The hashCode for relations is deterministic. (We use the unique id number.)

Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

getAttribNameMap

public java.util.Map getAttribNameMap()
Returns:
map from names to variables

fromXMLElement

public static Relation fromXMLElement(org.jdom.Element e,
                                      XMLFactory f)

toXMLElement

public org.jdom.Element toXMLElement()


Copyright © 2004-2008 Stanford SUIF Compiler Group. All Rights Reserved.