class_docstr: A map-to-arrays container, with deterministic Reservoir Sampling.
  
  Items are added with an associated key. Items may be retrieved by key, and
  a list of keys can also be retrieved. If size is not zero, then it dictates
  the maximum number of items that will be stored with each key. Once there are
  more items for a given key, they are replaced via reservoir sampling, such
  that each item has an equal probability of being included in the sample.
  
  Deterministic means that for any given seed and bucket size, the sequence of
  values that are kept for any given tag will always be the same, and that this
  is independent of any insertions on other tags. That is:
  
  >>> separate_reservoir = reservoir.Reservoir(10)
  >>> interleaved_reservoir = reservoir.Reservoir(10)
  >>> for i in range(100):
  >>>   separate_reservoir.AddItem('key1', i)
  >>> for i in range(100):
  >>>   separate_reservoir.AddItem('key2', i)
  >>> for i in range(100):
  >>>   interleaved_reservoir.AddItem('key1', i)
  >>>   interleaved_reservoir.AddItem('key2', i)
  
  separate_reservoir and interleaved_reservoir will be in identical states.
  
  See: https://en.wikipedia.org/wiki/Reservoir_sampling
  
  Adding items has amortized O(1) runtime.
  
  Fields:
    always_keep_last: Whether the latest seen sample is always at the
      end of the reservoir. Defaults to True.
    size: An integer of the maximum number of samples.
docstr: Add a new item to the Reservoir with the given tag.
  
  If the reservoir has not yet reached full size, the new item is guaranteed
  to be added. If the reservoir is full, then behavior depends on the
  always_keep_last boolean.
  
  If always_keep_last was set to true, the new item is guaranteed to be added
  to the reservoir, and either the previous last item will be replaced, or
  (with low probability) an older item will be replaced.
  
  If always_keep_last was set to false, then the new item will replace an
  old item with low probability.
  
  If f is provided, it will be applied to transform item (lazily, iff item is
    going to be included in the reservoir).
  
  Args:
    key: The key to store the item under.
    item: The item to add to the reservoir.
    f: An optional function to transform the item prior to addition.
docstr_tok: ["Add","a","new","item","to","the","Reservoir","with","the","given","tag",".","If","the","reservoir","has","not","yet","reached","full","size",",","the","new","item","is","guaranteed","to","be","added",".","If","the","reservoir","is","full",",","then","behavior","depends","on","the","always_keep_last","boolean",".","If","always_keep_last","was","set","to","true",",","the","new","item","is","guaranteed","to","be","added","to","the","reservoir",",","and","either","the","previous","last","item","will","be","replaced",",","or","(","with","low","probability",")","an","older","item","will","be","replaced",".","If","always_keep_last","was","set","to","false",",","then","the","new","item","will","replace","an","old","item","with","low","probability",".","If","f","is","provided",",","it","will","be","applied","to","transform","item","(","lazily",",","iff","item","is","going","to","be","included","in","the","reservoir",")",".","Args",":","key",":","The","key","to","store","the","item","under",".","item",":","The","item","to","add","to","the","reservoir",".","f",":","An","optional","function","to","transform","the","item","prior","to","addition","."]
code: def AddItem(self, key, item, f=lambda x: x):
      """Add a new item to the Reservoir with the given tag.
  
      If the reservoir has not yet reached full size, the new item is guaranteed
      to be added. If the reservoir is full, then behavior depends on the
      always_keep_last boolean.
  
      If always_keep_last was set to true, the new item is guaranteed to be added
      to the reservoir, and either the previous last item will be replaced, or
      (with low probability) an older item will be replaced.
  
      If always_keep_last was set to false, then the new item will replace an
      old item with low probability.
  
      If f is provided, it will be applied to transform item (lazily, iff item is
        going to be included in the reservoir).
  
      Args:
        key: The key to store the item under.
        item: The item to add to the reservoir.
        f: An optional function to transform the item prior to addition.
      """
      with self._mutex:
          bucket = self._buckets[key]
      bucket.AddItem(item, f)
  
file_path: tensorboard/tensorboard/backend/event_processing/reservoir.py
imports: import collections
  import random
  import threading
label_desc: Use image node_id 4 for calling the Reservoir obj's underlying member method code with example usage: obj.AddItem(key, item, f) without return types