class_docstr: Data manager for sampling data, use reservoir sampling.
      
docstr: Create a _ReservoirBucket instance.
  
  Args:
      max_size: The maximum size of reservoir bucket. If max_size is
          zero, the bucket has unbounded size.
      random_instance: The random number generator. If not specified,
          default to random.Random(0)
      num_item_index: The index of data to add.
  
  Raises:
      ValueError: If args max_size is not a nonnegative integer.
docstr_tok: ["Create","a","_ReservoirBucket","instance",".","Args",":","max_size",":","The","maximum","size","of","reservoir","bucket",".","If","max_size","is","zero",",","the","bucket","has","unbounded","size",".","random_instance",":","The","random","number","generator",".","If","not","specified",",","default","to","random.Random","(","0",")","num_item_index",":","The","index","of","data","to","add",".","Raises",":","ValueError",":","If","args","max_size","is","not","a","nonnegative","integer","."]
code: def __init__(self, max_size, random_instance=None):
      """Create a _ReservoirBucket instance.
  
      Args:
          max_size: The maximum size of reservoir bucket. If max_size is
              zero, the bucket has unbounded size.
          random_instance: The random number generator. If not specified,
              default to random.Random(0)
          num_item_index: The index of data to add.
  
      Raises:
          ValueError: If args max_size is not a nonnegative integer.
      """
      if max_size < 0 or max_size != round(max_size):
          raise ValueError("Max_size must be nonnegative integer.")
      self._max_size = max_size
      self._random = (
          random_instance
          if random_instance is not None
          else random.Random(0)
      )
      self._items = []
      self._mutex = threading.Lock()
      self._num_items_index = 0
  
      self.max_scalar = None
      self.min_scalar = None
  
      # improve performance when data is monotonous
      self._last_special = False
  
imports: import collections
  import random
  import threading
label_desc: Use image node_id 1 to create a new _ReservoirBucket object from inherited base classes: object with example: obj = _ReservoirBucket(max_size, random_instance)