Class RefCountedSet<K>

java.lang.Object
com.espertech.esper.common.internal.collection.RefCountedSet<K>

public class RefCountedSet<K> extends Object
reference-counting set based on a HashMap implementation that stores keys and a reference counter for each unique key value. Each time the same key is added, the reference counter increases. Each time a key is removed, the reference counter decreases.
  • Field Details

  • Constructor Details

    • RefCountedSet

      public RefCountedSet()
      Constructor.
    • RefCountedSet

      public RefCountedSet(Map<K,Integer> refSet, int numValues)
  • Method Details

    • clear

      public void clear()
      Clear out the collection.
    • add

      public boolean add(K key)
      Add a key to the set. Add with a reference count of one if the key didn't exist in the set. Increase the reference count by one if the key already exists. Return true if this is the first time the key was encountered, or false if key is already in set.
      Parameters:
      key - to add
      Returns:
      true if the key is not in the set already, false if the key is already in the set
    • add

      public void add(K key, int numReferences)
      Add a key to the set with the given number of references.
      Parameters:
      key - to add
      numReferences - initial number of references
    • remove

      public boolean remove(K key)
      Removed a key to the set. Removes the key if the reference count is one. Decreases the reference count by one if the reference count is more then one. Return true if the reference count was one and the key thus removed, or false if key is stays in set.
      Parameters:
      key - to add
      Returns:
      true if the key is removed, false if it stays in the set
      Throws:
      IllegalStateException - is a key is removed that wasn't added to the map
    • removeAll

      public boolean removeAll(K key)
      Remove a key from the set regardless of the number of references.
      Parameters:
      key - to add
      Returns:
      true if the key is removed, false if the key was not found
      Throws:
      IllegalStateException - if a key is removed that wasn't added to the map
    • entryIterator

      public Iterator<Map.Entry<K,Integer>> entryIterator()
      Returns an iterator over the entry set.
      Returns:
      entry set iterator
    • keyIterator

      public Iterator<K> keyIterator()
      Returns a key iterator.
      Returns:
      key iterator
    • size

      public int size()
      Returns the number of values in the collection.
      Returns:
      size
    • getRefSet

      public Map<K,Integer> getRefSet()
    • getNumValues

      public int getNumValues()
    • setNumValues

      public void setNumValues(int numValues)
    • writePointsDouble

      public static void writePointsDouble(DataOutput output, RefCountedSet<Double> valueSet) throws IOException
      NOTE: Code-generation-invoked method, method name and parameter order matters
      Parameters:
      output - output
      valueSet - values
      Throws:
      IOException - io error
    • readPointsDouble

      public static RefCountedSet<Double> readPointsDouble(DataInput input) throws IOException
      NOTE: Code-generation-invoked method, method name and parameter order matters
      Parameters:
      input - input
      Returns:
      values
      Throws:
      IOException - io error