Class SparseMultiset<T,K>

java.lang.Object
dev.kkorolyov.flub.data.SparseMultiset<T,K>
All Implemented Interfaces:
Iterable<T>

public final class SparseMultiset<T,K> extends Object implements Iterable<T>
A collection of T elements supporting multiple K keys/markers on individual elements. Provides for efficient retrieval of all elements associated with a given subset of keys.
  • Constructor Details

    • SparseMultiset

      public SparseMultiset()
  • Method Details

    • get

      public T get(int i)
      Returns the element at index i.
    • get

      public Iterable<T> get(Iterable<? extends K> keys)
      Returns all elements associated with all keys.
    • add

      public int add(T element)
      Adds a new element and returns its index to use for subsequent modifications.
      Throws:
      IllegalArgumentException - if element is null
      See Also:
    • remove

      public boolean remove(int i)
      Removes element at index i and returns whether such an element existed.
    • put

      public void put(int i, Iterable<? extends K> keys)
      Associates keys with element at index i.
    • remove

      public void remove(int i, Iterable<? extends K> keys)
      Removes associations to keys for element at index i.
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object