All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.crobox.clickhouse.balancing.iterator.CircularIteratorSet.scala Maven / Gradle / Ivy

package com.crobox.clickhouse.balancing.iterator

import scala.collection.{mutable, AbstractIterator}

class CircularIteratorSet[T](seed: Seq[T] = Seq.empty) extends AbstractIterator[T] {

  private var internalIterator         = Iterator.continually(seed).flatten
  private val elements: mutable.Set[T] = mutable.HashSet(seed: _*)

  def add(element: T): Unit = {
    elements += element
    internalIterator = Iterator.continually(elements).flatten
  }

  def remove(element: T): Unit = {
    elements -= element
    internalIterator = Iterator.continually(elements).flatten
  }

  override def hasNext: Boolean = elements.nonEmpty

  override def next(): T = internalIterator.next()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy