class_docstr: A container for items from a stream, that implements reservoir sampling.
  
  It always stores the most recent item as its final item.
docstr: Create the _ReservoirBucket.
  
  Args:
    _max_size: The maximum size the reservoir bucket may grow to. If size is
      zero, the bucket has unbounded size.
    _random: The random number generator to use. If not specified, defaults to
      random.Random(0).
    always_keep_last: Whether the latest seen item should always be included
      in the end of the bucket.
  
  Raises:
    ValueError: if the size is not a nonnegative integer.
docstr_tok: ["Create","the","_ReservoirBucket",".","Args",":","_max_size",":","The","maximum","size","the","reservoir","bucket","may","grow","to",".","If","size","is","zero",",","the","bucket","has","unbounded","size",".","_random",":","The","random","number","generator","to","use",".","If","not","specified",",","defaults","to","random.Random","(","0",")",".","always_keep_last",":","Whether","the","latest","seen","item","should","always","be","included","in","the","end","of","the","bucket",".","Raises",":","ValueError",":","if","the","size","is","not","a","nonnegative","integer","."]
code: def __init__(self, _max_size, _random=None, always_keep_last=True):
      """Create the _ReservoirBucket.
  
      Args:
        _max_size: The maximum size the reservoir bucket may grow to. If size is
          zero, the bucket has unbounded size.
        _random: The random number generator to use. If not specified, defaults to
          random.Random(0).
        always_keep_last: Whether the latest seen item should always be included
          in the end of the bucket.
  
      Raises:
        ValueError: if the size is not a nonnegative integer.
      """
      if _max_size < 0 or _max_size != round(_max_size):
          raise ValueError(
              "_max_size must be nonnegative int, was %s" % _max_size
          )
      self.items = []
      # This mutex protects the internal items, ensuring that calls to Items and
      # AddItem are thread-safe
      self._mutex = threading.Lock()
      self._max_size = _max_size
      self._num_items_seen = 0
      if _random is not None:
          self._random = _random
      else:
          self._random = random.Random(0)
      self.always_keep_last = always_keep_last
  
file_path: tensorboard/tensorboard/backend/event_processing/reservoir.py
imports: import collections
  import random
  import threading
label_desc: Use image node_id 1 to create a new _ReservoirBucket object  with example: obj = _ReservoirBucket(_max_size, _random, always_keep_last)