Class BitSetBag

java.lang.Object
uk.ac.starlink.ttools.moc.BitSetBag
All Implemented Interfaces:
IndexBag

public class BitSetBag extends Object implements IndexBag
IndexBag implementation based on a BitSet. It can hold non-negative numbers up to a given limit.

A fixed amount of memory is used, namely size bits (plus small change).

Since:
28 Jan 2025
Author:
Mark Taylor
  • Constructor Details

    • BitSetBag

      public BitSetBag(int size)
      Constructor. Non-negative integers smaller than the given size value can be held.
      Parameters:
      size - one greater than largest permitted value
  • Method Details

    • addIndex

      public void addIndex(long lval)
      Description copied from interface: IndexBag
      Adds an index to this bag. If the index is already present, there is no effect.

      If the index is outside of the range permitted by this bag, behaviour is undefined.

      Specified by:
      addIndex in interface IndexBag
      Parameters:
      lval - integer to add
    • hasIndex

      public boolean hasIndex(long lval)
      Description copied from interface: IndexBag
      Indicates whether the given index has previously been added to this bag.

      If the index is outside of the range permitted by this bag, behaviour is undefined.

      Specified by:
      hasIndex in interface IndexBag
      Parameters:
      lval - integer to check
      Returns:
      true iff the given index has previously been added
    • getCount

      public long getCount()
      Description copied from interface: IndexBag
      Returns the number of distinct indices in this bag.
      Specified by:
      getCount in interface IndexBag
      Returns:
      count of added integers
    • sortedLongIterator

      public PrimitiveIterator.OfLong sortedLongIterator()
      Description copied from interface: IndexBag
      Returns an iterator over all the integers added to this bag, supplied in ascending order.
      Specified by:
      sortedLongIterator in interface IndexBag
      Returns:
      sorted iterator over indices