edu.rice.cs.plt.collect
Class LazyRelationIndex<K,V>

java.lang.Object
  extended by edu.rice.cs.plt.collect.LazyRelationIndex<K,V>
All Implemented Interfaces:
RelationIndex<K,V>, SizedIterable<Pair<K,V>>, java.io.Serializable, java.lang.Iterable<Pair<K,V>>

public class LazyRelationIndex<K,V>
extends java.lang.Object
implements RelationIndex<K,V>, java.io.Serializable

A RelationIndex implementation defined lazily in terms of the contents of a dynamic list of pairs. Requires essentially no space, but is far less efficient than a ConcreteRelationIndex. Does not support mutation. Defined for use in relations in which a particular mapping is unlikely to be used heavily.

See Also:
Serialized Form

Constructor Summary
LazyRelationIndex(java.lang.Iterable<? extends Pair<K,V>> pairs)
           
LazyRelationIndex(java.util.Set<Pair<K,V>> pairs)
           
 
Method Summary
 void added(K key, V value)
          Requests that the index be updated to reflect the addition of the given key/value pair.
 void cleared()
          Requests that the index be cleared to reflect the current state of the relation.
 boolean contains(java.lang.Object key, java.lang.Object value)
          Whether the given key-value mapping occurs.
 boolean hasFixedSize()
          true if this iterable is known to have a fixed size.
 boolean isEmpty()
          Whether the iterable does not contain any elements.
 boolean isInfinite()
          true if the iterable is known to have infinite size.
 boolean isStatic()
          true if this iterable is unchanging.
 java.util.Iterator<Pair<K,V>> iterator()
          Iterates through all key-value pairs in the index.
 PredicateSet<K> keys()
          A dynamically-updating view of all keys mapping to at least one value.
 PredicateSet<V> match(K key)
          A dynamically-updating view of all values matching key.
 void removed(K key, V value)
          Requests that the index be updated to reflect the removal of the given key/value pair.
 int size()
          Compute the number of elements in the iterable.
 int size(int bound)
          Compute the number of elements in the iterable, up to the given bound.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LazyRelationIndex

public LazyRelationIndex(java.lang.Iterable<? extends Pair<K,V>> pairs)

LazyRelationIndex

public LazyRelationIndex(java.util.Set<Pair<K,V>> pairs)
Method Detail

isEmpty

public boolean isEmpty()
Description copied from interface: SizedIterable
Whether the iterable does not contain any elements.

Specified by:
isEmpty in interface SizedIterable<Pair<K,V>>

size

public int size()
Description copied from interface: SizedIterable
Compute the number of elements in the iterable. If the size is infinite or too large to be represented as an int, Integer.MAX_VALUE should be returned. Otherwise, next() may be safely invoked on the iterator exactly this number of times.

Specified by:
size in interface SizedIterable<Pair<K,V>>

size

public int size(int bound)
Description copied from interface: SizedIterable
Compute the number of elements in the iterable, up to the given bound. If the size is infinite or greater than bound, bound is returned.

Specified by:
size in interface SizedIterable<Pair<K,V>>
Parameters:
bound - Maximum result. Assumed to be nonnegative.

isInfinite

public boolean isInfinite()
Description copied from interface: SizedIterable
true if the iterable is known to have infinite size. If true, an iterator over the iterable in its current state will never return false from hasNext().

Specified by:
isInfinite in interface SizedIterable<Pair<K,V>>

hasFixedSize

public boolean hasFixedSize()
Description copied from interface: SizedIterable
true if this iterable is known to have a fixed size. This is the case if the iterable is immutable, or if changes can only replace values, not remove or add them. An infinite iterable may be fixed if it is guaranteed to never become finite.

Specified by:
hasFixedSize in interface SizedIterable<Pair<K,V>>

isStatic

public boolean isStatic()
Description copied from interface: SizedIterable
true if this iterable is unchanging. This implies that hasFixedSize() is true, and that iterator() will always return the same (either == or equal() and immutable) elements in the same order. ("Immutable" here means that equals() invocations are consistent over time -- if two objects are equal, they will never become inequal, and vice versa.)

Specified by:
isStatic in interface SizedIterable<Pair<K,V>>

contains

public boolean contains(java.lang.Object key,
                        java.lang.Object value)
Description copied from interface: RelationIndex
Whether the given key-value mapping occurs.

Specified by:
contains in interface RelationIndex<K,V>

keys

public PredicateSet<K> keys()
Description copied from interface: RelationIndex
A dynamically-updating view of all keys mapping to at least one value. Mutation (removal), if supported, will be automatically reflected in the relation being indexed.

Specified by:
keys in interface RelationIndex<K,V>

match

public PredicateSet<V> match(K key)
Description copied from interface: RelationIndex
A dynamically-updating view of all values matching key. May be empty. Mutation, if supported, will be automatically reflected in the relation being indexed.

Specified by:
match in interface RelationIndex<K,V>

iterator

public java.util.Iterator<Pair<K,V>> iterator()
Description copied from interface: RelationIndex
Iterates through all key-value pairs in the index.

Specified by:
iterator in interface RelationIndex<K,V>
Specified by:
iterator in interface java.lang.Iterable<Pair<K,V>>

added

public void added(K key,
                  V value)
Description copied from interface: RelationIndex
Requests that the index be updated to reflect the addition of the given key/value pair. Assumes the pair is not already present.

Specified by:
added in interface RelationIndex<K,V>

removed

public void removed(K key,
                    V value)
Description copied from interface: RelationIndex
Requests that the index be updated to reflect the removal of the given key/value pair. Assumes the pair is present.

Specified by:
removed in interface RelationIndex<K,V>

cleared

public void cleared()
Description copied from interface: RelationIndex
Requests that the index be cleared to reflect the current state of the relation. Assumes the index is non-empty.

Specified by:
cleared in interface RelationIndex<K,V>