Class IndexMultimap<A,B>

All Implemented Interfaces:
Multimap<A,B>, Iterable<Map.Entry<A,B>>, Collection<Map.Entry<A,B>>, BiPredicate<A,B>, Set<Map.Entry<A,B>>

public class IndexMultimap<A,B> extends AbstractMultimap<A,B>
Optimized Implementation using bit sets for both directions.
  • Constructor Details

    • IndexMultimap

      public IndexMultimap(IndexMultimap<A,B> m)
    • IndexMultimap

      public IndexMultimap(Index<A> domIndex, Index<B> ranIndex)
  • Method Details

    • getDomainIndex

      public Index<A> getDomainIndex()
    • getRangeIndex

      public Index<B> getRangeIndex()
    • add

      public boolean add(int i, int j)
      Special for indexed bases multimaps, is NOT an override.
    • remove

      public boolean remove(int i, int j)
      Special for indexed bases multimaps, is NOT an override.
    • contains

      public boolean contains(int i, int j)
      Special for indexed bases multimaps, is NOT an override.
    • size

      public int size()
      Specified by:
      size in interface Collection<A>
      Specified by:
      size in interface Set<A>
      Specified by:
      size in class AbstractCollection<Map.Entry<A,B>>
    • iterator

      public Iterator<Map.Entry<A,B>> iterator()
      Specified by:
      iterator in interface Collection<A>
      Specified by:
      iterator in interface Iterable<A>
      Specified by:
      iterator in interface Set<A>
      Specified by:
      iterator in class AbstractCollection<Map.Entry<A,B>>
    • contains

      public boolean contains(A a, B b)
      Description copied from interface: Multimap
      Whether this multimap contains a pair with the given components.
      Specified by:
      contains in interface Multimap<A,B>
      Overrides:
      contains in class AbstractMultimap<A,B>
      Parameters:
      a - the left component of the pair to add.
      b - the right component of the pair to add.
    • containsUnchecked

      public boolean containsUnchecked(Object a, Object b)
      Specified by:
      containsUnchecked in interface Multimap<A,B>
      Overrides:
      containsUnchecked in class AbstractMultimap<A,B>
    • contains

      public boolean contains(Object x)
      Specified by:
      contains in interface Collection<A>
      Specified by:
      contains in interface Set<A>
      Overrides:
      contains in class AbstractCollection<Map.Entry<A,B>>
    • add

      public boolean add(A a, B b)
      Description copied from interface: Multimap
      Adds a pair to this multimap. This operation must be stable: adding a pair that equals any pair contained in this multimap componentwise must not change this multimap.
      Specified by:
      add in interface Multimap<A,B>
      Overrides:
      add in class AbstractMultimap<A,B>
      Parameters:
      a - the left component of the pair to add.
      b - the right component of the pair to add.
      Returns:
      true if this multimap has been changed by this operation, false otherwise.
    • add

      public boolean add(Map.Entry<A,B> e)
      Specified by:
      add in interface Collection<A>
      Specified by:
      add in interface Set<A>
      Overrides:
      add in class AbstractCollection<Map.Entry<A,B>>
    • remove

      public boolean remove(A a, B b)
      Description copied from interface: Multimap
      Removes a pair from this this multimap. Removing a pair that equals no pair contained in this multimap componentwise must not change this multimap.
      Specified by:
      remove in interface Multimap<A,B>
      Overrides:
      remove in class AbstractMultimap<A,B>
      Parameters:
      a - the left component of the pair to remove.
      b - the right component of the pair to remove.
      Returns:
      true if this multimap has been changed by this operation, false otherwise.
    • removeUnchecked

      public boolean removeUnchecked(Object a, Object b)
      Specified by:
      removeUnchecked in interface Multimap<A,B>
      Overrides:
      removeUnchecked in class AbstractMultimap<A,B>
    • domain

      public Set<A> domain()
      Description copied from interface: Multimap
      Returns the set of left components of pairs in this multimap.

      The returned set is backed by this multimap, such that changes to this multimap are reflected by the set. The behavior of modifications of this multimap concurrent to iteration of the set is unspecified.

      If this multimap supports the removeDomain operation, then the returned set and its iterators must support the remove operation, and changes by these operations must be reflected by this multimap.

      Specified by:
      domain in interface Multimap<A,B>
      Overrides:
      domain in class AbstractMultimap<A,B>
      Returns:
      the set of left components of pairs in this multimap.
    • range

      public Set<B> range()
      Description copied from interface: Multimap
      Returns the set of right components of pairs in this multimap.

      If this multimap supports the removeRange operation, then the returned set and its iterators must support the remove operation.

      Specified by:
      range in interface Multimap<A,B>
      Overrides:
      range in class AbstractMultimap<A,B>
      Returns:
      the set of right components of pairs in this multimap.
    • removeDomain

      public boolean removeDomain(A a)
      Description copied from interface: Multimap
      Removes all pairs with a given left component from this multimap. The effect of the implementation on this multimap must be equivalent to the following code:
       removeDomain(final A a) {
         for (B b : new HashSet<B>(range())) remove(a, b) ;
       }
       
      Specified by:
      removeDomain in interface Multimap<A,B>
      Overrides:
      removeDomain in class AbstractMultimap<A,B>
      Parameters:
      a - the left component of all pairs to remove.
      Returns:
      true if this multimap has been changed by this operation, false otherwise.
    • image

      public IndexSet<B> image(A a)
      Description copied from interface: Multimap
      Returns the set of right components of pairs with a given left component in this multimap.

      The returned set need not be modifiable. The behaviour of this multimap after successfully modifying the returned set is unspecified.

      Specified by:
      image in interface Multimap<A,B>
      Overrides:
      image in class AbstractMultimap<A,B>
      Parameters:
      a - a left component.
      Returns:
      the set of right components of pairs with a left component that equals(a) in this multimap.
    • imageUnchecked

      public IndexSet<B> imageUnchecked(Object a)
      Specified by:
      imageUnchecked in interface Multimap<A,B>
      Overrides:
      imageUnchecked in class AbstractMultimap<A,B>
      See Also:
    • imageAll

      public IndexSet<B> imageAll(Collection<? extends A> c)
      Description copied from interface: Multimap
      Returns the set of right components of pairs in this multimap, which have a left component in the given set.
      Specified by:
      imageAll in interface Multimap<A,B>
      Overrides:
      imageAll in class AbstractMultimap<A,B>
    • imageAllUnchecked

      public IndexSet<B> imageAllUnchecked(Collection<?> c)
      Specified by:
      imageAllUnchecked in interface Multimap<A,B>
      Overrides:
      imageAllUnchecked in class AbstractMultimap<A,B>
      See Also:
    • preimage

      public IndexSet<A> preimage(B b)
      Description copied from interface: Multimap
      Returns the set of left components of pairs with a given right component in this multimap.

      The returned set need not be modifiable. The behaviour of this multimap after successfully modifying the returned set is unspecified.

      Specified by:
      preimage in interface Multimap<A,B>
      Overrides:
      preimage in class AbstractMultimap<A,B>
      Parameters:
      b - a right component.
      Returns:
      the set of left components of pairs with a right component that equals(b) in this multimap.