Class: DataStructuresRMolinari::MaxValSegmentTree
- Inherits:
-
Object
- Object
- DataStructuresRMolinari::MaxValSegmentTree
- Extended by:
- Forwardable
- Defined in:
- lib/data_structures_rmolinari.rb
Overview
Takes an array A and tells us what the maximum value is on a subinterval i..j in O(log n) time.
TODO:
-
allow min val too
-
add a flag to the initializer
-
call it ExtremalValSegment tree or something similar
-
Instance Method Summary collapse
-
#initialize(data) ⇒ MaxValSegmentTree
constructor
A new instance of MaxValSegmentTree.
Constructor Details
#initialize(data) ⇒ MaxValSegmentTree
35 36 37 38 39 40 41 42 |
# File 'lib/data_structures_rmolinari.rb', line 35 def initialize(data) @structure = GenericSegmentTree.new( combine: ->(a, b) { [a, b].max }, single_cell_array_val: ->(i) { data[i] }, size: data.size, identity: -Float::INFINITY ) end |