Class IntBitSet

  • All Implemented Interfaces:
    PositiveIntSet

    public class IntBitSet
    extends java.lang.Object
    implements PositiveIntSet
    A set of non-zero positive ints. This is better (size) than IntHashSet unless the expected max int to be contained is > size of the set * 100 or you need to store negative ints This impl is for use in a single thread case only This impl supports offset, to let this bit set store items in a range n → n + small number If using offset, you must add ints in a range equal to or above the offset
    • Field Detail

      • set

        private final java.util.BitSet set
      • size

        private int size
      • offset

        private final int offset
    • Constructor Detail

      • IntBitSet

        public IntBitSet()
        Construct an IntBitSet capable of holding ints from 0 to 63, (perhaps plus an offset)
      • IntBitSet

        public IntBitSet​(int maxInt)
        Construct an IntBitSet capable of holding ints from 0 to maxInt (perhaps plus an offset)
        Parameters:
        maxInt - the biggest int (perhaps plus an offset) that can be held without growing the space
      • IntBitSet

        public IntBitSet​(int maxAdjKey,
                         int offset)
    • Method Detail

      • getOffset

        public int getOffset()
        Returns:
        the current offset
      • clear

        public void clear()
        empty the IntBitSet. keeps the offset
        Specified by:
        clear in interface PositiveIntSet
      • contains

        public boolean contains​(int key)
        Specified by:
        contains in interface PositiveIntSet
        Parameters:
        key - - the integer (not adjusted for offset)
        Returns:
        -
      • find

        public int find​(int element)
        Specified by:
        find in interface PositiveIntSet
        Parameters:
        element - an item which may be in the set
        Returns:
        -1 if the item is not in the set, or a position value that can be used with iterators to start at that item.
      • add

        public boolean add​(int original_key)
        Specified by:
        add in interface PositiveIntSet
        Parameters:
        original_key - - the int to add to the set
        Returns:
        true if this set did not already contain the specified element
      • remove

        public boolean remove​(int original_key)
        Specified by:
        remove in interface PositiveIntSet
        Parameters:
        original_key - -
        Returns:
        true if this key was removed, false if not present
      • size

        public int size()
        Specified by:
        size in interface PositiveIntSet
        Returns:
        the number of elements in this set
      • getSpaceUsed_in_bits_no_overhead

        public int getSpaceUsed_in_bits_no_overhead()
      • getSpaceUsed_in_words_no_overhead

        public int getSpaceUsed_in_words_no_overhead()
        Returns:
        space used in 32 bit words
      • getLargestMenber

        public int getLargestMenber()
        Returns:
        largest int in the set If the set has no members, 0 is returned
      • get

        public int get​(int position)
        Description copied from interface: PositiveIntSet
        For FSBagIndex low level iterator use DOESN"T WORK WITH INCREMENTING position VALUES
        Specified by:
        get in interface PositiveIntSet
        Parameters:
        position - - get the element at this position. This is for iterator use only, and is not related to any key
        Returns:
        the element
      • moveToFirst

        public int moveToFirst()
        Description copied from interface: PositiveIntSet
        For FSBagIndex low level iterator use
        Specified by:
        moveToFirst in interface PositiveIntSet
        Returns:
        the position of the first element, or -1;
      • moveToLast

        public int moveToLast()
        Description copied from interface: PositiveIntSet
        For FSBagIndex low level iterator use
        Specified by:
        moveToLast in interface PositiveIntSet
        Returns:
        the position of the last element, or -1;
      • moveToNext

        public int moveToNext​(int position)
        Description copied from interface: PositiveIntSet
        For FSBagIndex low level iterator use
        Specified by:
        moveToNext in interface PositiveIntSet
        Parameters:
        position - -
        Returns:
        the position of the next element, or -1;
      • moveToPrevious

        public int moveToPrevious​(int position)
        Description copied from interface: PositiveIntSet
        For FSBagIndex low level iterator use
        Specified by:
        moveToPrevious in interface PositiveIntSet
        Parameters:
        position - -
        Returns:
        the position of the next element, or -1;
      • isValid

        public boolean isValid​(int position)
        This impl depends on position always pointing to a valid (== non 0) element of the set, when it should be valid
        Specified by:
        isValid in interface PositiveIntSet
        Parameters:
        position - -
        Returns:
        true if the position is between the first and last element inclusive.
      • bulkAddTo

        public void bulkAddTo​(IntVector v)
        Add all elements of this bit set to the passed in IntVector
        Specified by:
        bulkAddTo in interface PositiveIntSet
        Parameters:
        v - - to be added to
      • toIntArray

        public int[] toIntArray()
        Specified by:
        toIntArray in interface PositiveIntSet
        Returns:
        the set as an arbitrarily ordered int array
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object