data_structures_rmolinari 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,73 +10,16 @@ end
10
10
 
11
11
  # These define classes inside module DataStructuresRMolinari
12
12
  require_relative 'data_structures_rmolinari/algorithms'
13
+
13
14
  require_relative 'data_structures_rmolinari/disjoint_union'
14
15
  require_relative 'data_structures_rmolinari/c_disjoint_union' # version as a C extension
15
- require_relative 'data_structures_rmolinari/segment_tree_template'
16
+
17
+ require_relative 'data_structures_rmolinari/segment_tree'
18
+
16
19
  require_relative 'data_structures_rmolinari/heap'
17
20
  require_relative 'data_structures_rmolinari/max_priority_search_tree'
18
21
  require_relative 'data_structures_rmolinari/min_priority_search_tree'
19
22
 
20
23
  module DataStructuresRMolinari
21
- ########################################
22
- # Concrete instances of Segment Tree
23
- #
24
- # @todo consider moving these into generic_segment_tree.rb and renaming that file
25
-
26
- # A segment tree that for an array A(0...n) answers questions of the form "what is the maximum value in the subinterval A(i..j)?"
27
- # in O(log n) time.
28
- class MaxValSegmentTree
29
- extend Forwardable
30
-
31
- # Tell the tree that the value at idx has changed
32
- def_delegator :@structure, :update_at
33
-
34
- # @param data an object that contains values at integer indices based at 0, via +data[i]+.
35
- # - This will usually be an Array, but it could also be a hash or a proc.
36
- def initialize(data)
37
- @structure = SegmentTreeTemplate.new(
38
- combine: ->(a, b) { [a, b].max },
39
- single_cell_array_val: ->(i) { data[i] },
40
- size: data.size,
41
- identity: -Shared::INFINITY
42
- )
43
- end
44
-
45
- # The maximum value in A(i..j).
46
- #
47
- # The arguments must be integers in 0...(A.size)
48
- # @return the largest value in A(i..j) or -Infinity if i > j.
49
- def max_on(i, j)
50
- @structure.query_on(i, j)
51
- end
52
- end
53
-
54
- # A segment tree that for an array A(0...n) answers questions of the form "what is the index of the maximal value in the
55
- # subinterval A(i..j)?" in O(log n) time.
56
- class IndexOfMaxValSegmentTree
57
- extend Forwardable
58
-
59
- # Tell the tree that the value at idx has changed
60
- def_delegator :@structure, :update_at
61
-
62
- # @param (see MaxValSegmentTree#initialize)
63
- def initialize(data)
64
- @structure = SegmentTreeTemplate.new(
65
- combine: ->(p1, p2) { p1[1] >= p2[1] ? p1 : p2 },
66
- single_cell_array_val: ->(i) { [i, data[i]] },
67
- size: data.size,
68
- identity: nil
69
- )
70
- end
71
-
72
- # The index of the maximum value in A(i..j)
73
- #
74
- # The arguments must be integers in 0...(A.size)
75
- # @return (Integer, nil) the index of the largest value in A(i..j) or +nil+ if i > j.
76
- # - If there is more than one entry with that value, return one the indices. There is no guarantee as to which one.
77
- # - Return +nil+ if i > j
78
- def index_of_max_val_on(i, j)
79
- @structure.query_on(i, j)&.first # discard the value part of the pair, which is a bookkeeping
80
- end
81
- end
24
+ # Add things here if needed
82
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_structures_rmolinari
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rory Molinari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-27 00:00:00.000000000 Z
11
+ date: 2023-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: must_be
@@ -79,6 +79,7 @@ email: rorymolinari@gmail.com
79
79
  executables: []
80
80
  extensions:
81
81
  - ext/c_disjoint_union/extconf.rb
82
+ - ext/c_segment_tree_template/extconf.rb
82
83
  extra_rdoc_files: []
83
84
  files:
84
85
  - CHANGELOG.md
@@ -86,12 +87,17 @@ files:
86
87
  - Rakefile
87
88
  - ext/c_disjoint_union/disjoint_union.c
88
89
  - ext/c_disjoint_union/extconf.rb
90
+ - ext/c_segment_tree_template/extconf.rb
91
+ - ext/c_segment_tree_template/segment_tree_template.c
92
+ - ext/shared.c
89
93
  - lib/data_structures_rmolinari.rb
90
94
  - lib/data_structures_rmolinari/algorithms.rb
95
+ - lib/data_structures_rmolinari/c_segment_tree_template_impl.rb
91
96
  - lib/data_structures_rmolinari/disjoint_union.rb
92
97
  - lib/data_structures_rmolinari/heap.rb
93
98
  - lib/data_structures_rmolinari/max_priority_search_tree.rb
94
99
  - lib/data_structures_rmolinari/min_priority_search_tree.rb
100
+ - lib/data_structures_rmolinari/segment_tree.rb
95
101
  - lib/data_structures_rmolinari/segment_tree_template.rb
96
102
  - lib/data_structures_rmolinari/shared.rb
97
103
  homepage: https://github.com/rmolinari/data_structures