Package net.i2p.util

Class ArraySet<E>

All Implemented Interfaces:
Iterable<E>, Collection<E>, Set<E>
Direct Known Subclasses:
UnmodifiableSortedSet

public class ArraySet<E> extends AbstractSet<E> implements Set<E>
A small, fast Set with a maximum size, backed by a fixed-size array. Much more space-efficient than HashSet. Unsynchronized, not thread-safe. Null elements are not permitted. Not appropriate for large Sets that are modified. add(), remove(), and contains() are O(n). Warning: addAll() and the Collection constructor are O(n**2).
Since:
0.9.25, moved to net.i2p.util in 0.9.55
  • Field Details

  • Constructor Details

    • ArraySet

      public ArraySet()
      A fixed capacity of MAX_CAPACITY. Adds over capacity will throw a SetFullException.
    • ArraySet

      public ArraySet(Set<? extends E> c)
      A fixed capacity of max(MAX_CAPACITY, c.size()) Adds over capacity will throw a SetFullException.
      Since:
      0.9.55
    • ArraySet

      public ArraySet(Set<? extends E> c, int capacity)
      A fixed capacity of max(capacity, c.size()) Adds over capacity will throw a SetFullException.
      Since:
      0.9.55
    • ArraySet

      public ArraySet(Collection<? extends E> c)
      A fixed capacity of max(MAX_CAPACITY, c.size()), which may be more than the resulting set size if there are duplicates in c. Adds over capacity will throw a SetFullException. Warning: O(n**2).
    • ArraySet

      public ArraySet(Collection<? extends E> c, int capacity)
      A fixed capacity of max(capacity, c.size()), which may be more than the resulting set size if there are duplicates in c. Adds over capacity will throw a SetFullException. Warning: O(n**2).
      Since:
      0.9.55
    • ArraySet

      public ArraySet(int capacity)
      Adds over capacity will throw a SetFullException.
      Parameters:
      capacity - the maximum size
      Throws:
      IllegalArgumentException - if capacity less than 1.
    • ArraySet

      public ArraySet(int capacity, boolean throwOnFull)
      If throwOnFull is false, adds over capacity will overwrite starting at slot zero. This breaks the AbstractCollection invariant that "a Collection will always contain the specified element after add() returns", but it prevents unexpected exceptions. If throwOnFull is true, adds over capacity will throw a SetFullException.
      Parameters:
      capacity - the maximum size
      Throws:
      IllegalArgumentException - if capacity less than 1.
  • Method Details