Class BasicNaturalRelation

  • All Implemented Interfaces:
    VerboseAction, IBinaryNaturalRelation, java.io.Serializable, java.lang.Iterable<IntPair>

    public final class BasicNaturalRelation
    extends java.lang.Object
    implements IBinaryNaturalRelation, java.io.Serializable
    A relation between non-negative integers This implementation uses n IntVectors, to hold the first n y's associated with each x, and then 1 extra vector of SparseIntSet to hold the remaining ys.
    See Also:
    Serialized Form
    • Constructor Detail

      • BasicNaturalRelation

        public BasicNaturalRelation​(byte[] implementation,
                                    byte vectorImpl)
                             throws java.lang.IllegalArgumentException
        Parameters:
        implementation - a set of codes that represent how the first n IntVectors should be implemented.
        vectorImpl - a code that indicates how to represent the delegateStore. For example implementation = {SIMPLE_INT_VECTOR,TWO_LEVEL_INT_VECTOR,TWO_LEVEL_INT_VECTOR} will result in an implementation where the first 3 y's associated with each x are represented in IntVectors. The IntVector for the first y will be implemented with a SimpleIntVector, and the 2nd and 3rd are implemented with TwoLevelIntVector
        Throws:
        java.lang.IllegalArgumentException - if implementation is null
        java.lang.IllegalArgumentException - if implementation.length == 0
      • BasicNaturalRelation

        public BasicNaturalRelation()
    • Method Detail

      • add

        public boolean add​(int x,
                           int y)
                    throws java.lang.IllegalArgumentException
        Add (x,y) to the relation. This is performance-critical, so the implementation looks a little ugly in order to help out the compiler with redundancy elimination.
        Specified by:
        add in interface IBinaryNaturalRelation
        Returns:
        true iff the relation changes as a result of this call.
        Throws:
        java.lang.IllegalArgumentException
      • iterator

        public java.util.Iterator<IntPair> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<IntPair>
      • anyRelated

        public boolean anyRelated​(int x)
        Specified by:
        anyRelated in interface IBinaryNaturalRelation
        Returns:
        true iff there exists pair (x,y) for some y
      • getRelatedCount

        public int getRelatedCount​(int x)
                            throws java.lang.IllegalArgumentException
        Specified by:
        getRelatedCount in interface IBinaryNaturalRelation
        Returns:
        number of y s.t. R(x,y)
        Throws:
        java.lang.IllegalArgumentException
      • toString

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