Class Relation
java.lang.Object
edu.harvard.seas.pl.abcdatalog.engine.topdown.Relation
- Direct Known Subclasses:
QsqSupRelation
A relation, i.e., a set of tuples of a fixed arity with an associated attribute schema of the
same arity.
-
Field Summary
Modifier and TypeFieldDescriptionfinal int
The fixed arity of this relation.protected TermSchema
The attribute schema of this relation.The tuples of this relation. -
Constructor Summary
ConstructorDescriptionRelation
(int arity) Constructs an empty relation of the given arity.Constructs a relation from another relation.Relation
(TermSchema attributes) Constructs an empty relation with the given attribute schema. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Add a tuple of the proper arity to this relation.boolean
Add all the tuples of another relation to this relation.For each tuple t in this relation, creates a substitution by mapping each attribute in the schema to the corresponding element in t, and then creates a new relation by applying each substitution to the input tuple x.boolean
Returns whether this relation contains the input tuple x.boolean
Returns a new relation consisting of those tuples that meet the supplied predicate.Returns the attribute schema for this relation.int
hashCode()
boolean
isEmpty()
Returns whether the relation has any tuples.iterator()
joinAndProject
(Relation other, TermSchema schema) Creates a new relation by joining this relation with the other relation and projecting onto the supplied attribute schema.Creates a new relation that results from the projection of this relation.boolean
Remove all the tuples in other relation from this relation.void
renameAttributes
(TermSchema schema) Change the attribute schema of this relation to the supplied one, which must be of the same arity as this relation.int
size()
Returns the number of tuples in this relation.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
tuples
The tuples of this relation. -
attributes
The attribute schema of this relation. -
arity
public final int arityThe fixed arity of this relation.
-
-
Constructor Details
-
Relation
Constructs a relation from another relation.- Parameters:
other
- the other relation
-
Relation
Constructs an empty relation with the given attribute schema.- Parameters:
attributes
- the attribute schema
-
Relation
public Relation(int arity) Constructs an empty relation of the given arity. It has a default attribute schema.- Parameters:
arity
- the arity
-
-
Method Details
-
add
Add a tuple of the proper arity to this relation.- Parameters:
x
- the tuple- Returns:
- whether this relation has changed
-
addAll
Add all the tuples of another relation to this relation. The two relations must have the same arity.- Parameters:
other
- the other relation- Returns:
- whether this relation has changed
-
removeAll
Remove all the tuples in other relation from this relation. The two relations must have the same arity.- Parameters:
other
- the other relation- Returns:
- whether this relation has changed
-
filter
Returns a new relation consisting of those tuples that meet the supplied predicate.- Parameters:
f
- the predicate- Returns:
- the new relation
-
size
public int size()Returns the number of tuples in this relation.- Returns:
- the number of tuples
-
isEmpty
public boolean isEmpty()Returns whether the relation has any tuples.- Returns:
- whether the relation is empty
-
joinAndProject
Creates a new relation by joining this relation with the other relation and projecting onto the supplied attribute schema. If the schema has attributes not in either relation, those terms are null.- Parameters:
other
- the other relationschema
- the attribute schema- Returns:
- the new relation
-
applyTuplesAsSubstitutions
For each tuple t in this relation, creates a substitution by mapping each attribute in the schema to the corresponding element in t, and then creates a new relation by applying each substitution to the input tuple x.- Parameters:
x
- the input tuple- Returns:
- the new relation
-
project
Creates a new relation that results from the projection of this relation. The projection is described by a list of booleans, where a true value denotes that the column should be retained.- Parameters:
colsToKeep
- the description of the projection- Returns:
- the new relation
-
contains
Returns whether this relation contains the input tuple x.- Parameters:
x
- the input tuple- Returns:
- whether this relation contains x
-
getAttributes
Returns the attribute schema for this relation.- Returns:
- the attribute schema
-
renameAttributes
Change the attribute schema of this relation to the supplied one, which must be of the same arity as this relation.- Parameters:
schema
- the new schema
-
toString
-
hashCode
public int hashCode() -
equals
-
iterator
-