class_docstr: A Segment Tree data structure.
  
  https://en.wikipedia.org/wiki/Segment_tree
  
  Can be used as regular array, but with two important differences:
  
    a) Setting an item's value is slightly slower. It is O(lg capacity),
       instead of O(1).
    b) Offers efficient `reduce` operation which reduces the tree's values
       over some specified contiguous subsequence of items in the array.
       Operation could be e.g. min/max/sum.
  
  The data is stored in a list, where the length is 2 * capacity.
  The second half of the list stores the actual values for each index, so if
  capacity=8, values are stored at indices 8 to 15. The first half of the
  array contains the reduced-values of the different (binary divided)
  segments, e.g. (capacity=4):
  0=not used
  1=reduced-value over all elements (array indices 4 to 7).
  2=reduced-value over array indices (4 and 5).
  3=reduced-value over array indices (6 and 7).
  4-7: values of the tree.
  NOTE that the values of the tree are accessed by indices starting at 0, so
  `tree[0]` accesses `internal_array[4]` in the above example.
class_docstr_tok: ["A","Segment","Tree","data","structure",".","https",":","\/\/en.wikipedia.org\/wiki\/Segment_tree","Can","be","used","as","regular","array",",","but","with","two","important","differences",":","a",")","Setting","an","item","'s","value","is","slightly","slower",".","It","is","O","(","lg","capacity",")",",","instead","of","O","(","1",")",".","b",")","Offers","efficient","`","reduce","`","operation","which","reduces","the","tree","'s","values","over","some","specified","contiguous","subsequence","of","items","in","the","array",".","Operation","could","be","e.g",".","min\/max\/sum",".","The","data","is","stored","in","a","list",",","where","the","length","is","2","*","capacity",".","The","second","half","of","the","list","stores","the","actual","values","for","each","index",",","so","if","capacity=8",",","values","are","stored","at","indices","8","to","15",".","The","first","half","of","the","array","contains","the","reduced-values","of","the","different","(","binary","divided",")","segments",",","e.g",".","(","capacity=4",")",":","0=not","used","1=reduced-value","over","all","elements","(","array","indices","4","to","7",")",".","2=reduced-value","over","array","indices","(","4","and","5",")",".","3=reduced-value","over","array","indices","(","6","and","7",")",".","4-7",":","values","of","the","tree",".","NOTE","that","the","values","of","the","tree","are","accessed","by","indices","starting","at","0",",","so","`","tree","[","0","]","`","accesses","`","internal_array","[","4","]","`","in","the","above","example","."]
docstr: Initializes a Segment Tree object.
  
  Args:
      capacity: Total size of the array - must be a power of two.
      operation: Lambda obj, obj -> obj
          The operation for combining elements (eg. sum, max).
          Must be a mathematical group together with the set of
          possible values for array elements.
      neutral_element (Optional[obj]): The neutral element for
          `operation`. Use None for automatically finding a value:
          max: float("-inf"), min: float("inf"), sum: 0.0.
docstr_tok: ["Initializes","a","Segment","Tree","object",".","Args",":","capacity",":","Total","size","of","the","array","-","must","be","a","power","of","two",".","operation",":","Lambda","obj",",","obj","-",">","obj","The","operation","for","combining","elements","(","eg",".","sum",",","max",")",".","Must","be","a","mathematical","group","together","with","the","set","of","possible","values","for","array","elements",".","neutral_element","(","Optional","[","obj","]",")",":","The","neutral","element","for","`","operation","`",".","Use","None","for","automatically","finding","a","value",":","max",":","float","(","``","-inf","''",")",",","min",":","float","(","``","inf","''",")",",","sum",":","0.0","."]
code: def __init__(
      self,
      capacity: int,
      operation: Any,
      neutral_element: Optional[Any] = None,
  ):
      """Initializes a Segment Tree object.
  
      Args:
          capacity: Total size of the array - must be a power of two.
          operation: Lambda obj, obj -> obj
              The operation for combining elements (eg. sum, max).
              Must be a mathematical group together with the set of
              possible values for array elements.
          neutral_element (Optional[obj]): The neutral element for
              `operation`. Use None for automatically finding a value:
              max: float("-inf"), min: float("inf"), sum: 0.0.
      """
  
      assert (
          capacity > 0 and capacity & (capacity - 1) == 0
      ), "Capacity must be positive and a power of 2!"
      self.capacity = capacity
      if neutral_element is None:
          neutral_element = (
              0.0
              if operation is operator.add
              else float("-inf")
              if operation is max
              else float("inf")
          )
      self.neutral_element = neutral_element
      self.value = [self.neutral_element for _ in range(2 * capacity)]
      self.operation = operation
  
file_path: ray/rllib/execution/segment_tree.py
imports: import operator
  from typing import Any, Optional
label_desc: Use image node_id 1 to create a new SegmentTree object  with example: obj = SegmentTree(capacity, operation, neutral_element)