Class SparseSet


  • public class SparseSet
    extends java.lang.Object
    Sparse set representation of the set.
    Version:
    4.8
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int[] dense
      Dense array used within SparseSet functionality.
      int members
      It specifies number of elements in the SparseSet.
      int[] sparse
      Sparse array used within SparseSet functionality.
    • Constructor Summary

      Constructors 
      Constructor Description
      SparseSet​(int size)
      It creates a SparseSet with given upper limit on the value of the biggest element in the set.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean addMember​(int value)
      It adds an element to the set.
      void clear()
      It removes all the elements by setting the number of members to zero.
      boolean isEmpty()
      It returns true if the set is empty.
      boolean isMember​(int k)
      It checks if the specified element belongs to the set.
      void setSize​(int size)
      It sets the size of the SparseSet.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • sparse

        public int[] sparse
        Sparse array used within SparseSet functionality.
      • dense

        public int[] dense
        Dense array used within SparseSet functionality.
      • members

        public int members
        It specifies number of elements in the SparseSet.
    • Constructor Detail

      • SparseSet

        public SparseSet​(int size)
        It creates a SparseSet with given upper limit on the value of the biggest element in the set.
        Parameters:
        size - the upper limit for the SparseSet
    • Method Detail

      • isMember

        public boolean isMember​(int k)
        It checks if the specified element belongs to the set.
        Parameters:
        k - element for which the membership in the given set is checked.
        Returns:
        true if k belongs to the sparse set, false otherwise.
      • addMember

        public boolean addMember​(int value)
        It adds an element to the set.
        Parameters:
        value - value being added.
        Returns:
        true if the value was not present before and was added to the set, false otherwise.
      • setSize

        public void setSize​(int size)
        It sets the size of the SparseSet.
        Parameters:
        size - the assigned size of the set.
      • isEmpty

        public boolean isEmpty()
        It returns true if the set is empty.
        Returns:
        true if the set is empty, false otherwise.
      • clear

        public void clear()
        It removes all the elements by setting the number of members to zero.
      • toString

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