docstr: Build a Segment Tree data structure.
  
  https://en.wikipedia.org/wiki/Segment_tree
  
  Can be used as regular array that supports Index arrays, but with two
  important differences:
  
      a) setting item's value is slightly slower.
         It is O(lg capacity) instead of O(1).
      b) user has access to an efficient ( O(log segment size) )
         `reduce` operation which reduces `operation` over
         a contiguous subsequence of items in the array.
  
  :param capacity: (int) Total size of the array - must be a power of two.
  :param operation: (lambda (Any, Any): Any) operation for combining elements (eg. sum, max) must form a
      mathematical group together with the set of possible values for array elements (i.e. be associative)
  :param neutral_element: (Any) neutral element for the operation above. eg. float('-inf') for max and 0 for sum.
docstr_tok: ["Build","a","Segment","Tree","data","structure",".","https",":","\/\/en.wikipedia.org\/wiki\/Segment_tree","Can","be","used","as","regular","array","that","supports","Index","arrays",",","but","with","two","important","differences",":","a",")","setting","item","'s","value","is","slightly","slower",".","It","is","O","(","lg","capacity",")","instead","of","O","(","1",")",".","b",")","user","has","access","to","an","efficient","(","O","(","log","segment","size",")",")","`","reduce","`","operation","which","reduces","`","operation","`","over","a","contiguous","subsequence","of","items","in","the","array",".",":","param","capacity",":","(","int",")","Total","size","of","the","array","-","must","be","a","power","of","two",".",":","param","operation",":","(","lambda","(","Any",",","Any",")",":","Any",")","operation","for","combining","elements","(","eg",".","sum",",","max",")","must","form","a","mathematical","group","together","with","the","set","of","possible","values","for","array","elements","(","i.e",".","be","associative",")",":","param","neutral_element",":","(","Any",")","neutral","element","for","the","operation","above",".","eg",".","float","(","'-inf","'",")","for","max","and","0","for","sum","."]
code: def __init__(self, capacity, operation, neutral_element):
      """
      Build a Segment Tree data structure.
  
      https://en.wikipedia.org/wiki/Segment_tree
  
      Can be used as regular array that supports Index arrays, but with two
      important differences:
  
          a) setting item's value is slightly slower.
             It is O(lg capacity) instead of O(1).
          b) user has access to an efficient ( O(log segment size) )
             `reduce` operation which reduces `operation` over
             a contiguous subsequence of items in the array.
  
      :param capacity: (int) Total size of the array - must be a power of two.
      :param operation: (lambda (Any, Any): Any) operation for combining elements (eg. sum, max) must form a
          mathematical group together with the set of possible values for array elements (i.e. be associative)
      :param neutral_element: (Any) neutral element for the operation above. eg. float('-inf') for max and 0 for sum.
      """
      assert (
          capacity > 0 and capacity & (capacity - 1) == 0
      ), "capacity must be positive and a power of 2."
      self._capacity = capacity
      self._value = [neutral_element for _ in range(2 * capacity)]
      self._operation = operation
      self.neutral_element = neutral_element
  
file_path: stable-baselines/stable_baselines/common/segment_tree.py
imports: import numpy
label_desc: Use image node_id 1 to create a new SegmentTree object from inherited base classes: object with example: obj = SegmentTree(capacity, operation, neutral_element)