data_structures_rmolinari 0.5.7 → 0.5.8
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +9 -5
- data/ext/cc.h +4500 -1962
- data/lib/data_structures_rmolinari/algorithms.rb +34 -1
- data/lib/data_structures_rmolinari/heap.rb +2 -1
- data/lib/data_structures_rmolinari/max_priority_search_tree.rb +1 -1
- data/lib/data_structures_rmolinari/min_priority_search_tree.rb +2 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: da4fc2b27a4f5c1071af7965dac6d3363cbfcb350f1ff391e88e6f7145561822
|
|
4
|
+
data.tar.gz: 114c9f4fb025ded31a2a42832aa7376333be03e58fe72e94ff3a1822a0e433d3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f13b0ab86555fcb9d0cef6bdb788c20a4335ad2e08e17e2a58993bffa2bc0eec8beb7299af4a61ec6c033931534c14dd270cb157640c5402ddb7e6a1fa676156
|
|
7
|
+
data.tar.gz: b620688430c178d7e865b1cafd7b1628f0a9fb37bbb5aaba8879ab8b5f9563fa27f8c7c4368516940ede905a5bef5b02f3fb2c3e0263845d4103c6cb14492a5f
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -57,7 +57,7 @@ operations:
|
|
|
57
57
|
- `top_priority`, return the _priority_ of the top element
|
|
58
58
|
- `pop`, return the element with smallest priority and remove it from the structure
|
|
59
59
|
- `update(item, priority)`, update the priority of the given item, which must already be in the heap
|
|
60
|
-
- `update_by_delta(item, delta)`, update the
|
|
60
|
+
- `update_by_delta(item, delta)`, update the priority of the given item by adding delta to the priority; the item must already be in the heap
|
|
61
61
|
|
|
62
62
|
`top` and `top_priority` are O(1). The others are O(log n) where n is the number of items in the heap.
|
|
63
63
|
|
|
@@ -123,7 +123,7 @@ regions.
|
|
|
123
123
|
By default these data structures are immutable: once constructed they cannot be changed. But there is a constructor option that
|
|
124
124
|
makes the instance "dynamic". This allows us to delete the element at the root of the tree - the one with largest y value (smallest
|
|
125
125
|
for MinPST) - with the `delete_top!` method. This operation is important in certain algorithms, such as enumerating all maximal
|
|
126
|
-
empty rectangles (see the second paper by De et al[[DMNS2013]](#references)). Note that points can still not be added to the PST in
|
|
126
|
+
empty rectangles (see the second paper by De et al [[DMNS2013]](#references)). Note that points can still not be added to the PST in
|
|
127
127
|
any case, and choosing the dynamic option makes certain internal bookkeeping operations slower.
|
|
128
128
|
|
|
129
129
|
In [[DMNS2013]](#references) De et al. generalize the in-place structure to a _Min-max Priority Search Tree_ (MinmaxPST) that can
|
|
@@ -161,7 +161,7 @@ initializer. Figuring out the details requires some knowledge of the internal me
|
|
|
161
161
|
cp-algorithms.com is very helpful. See the implementations of the concrete classes `MaxValSegmentTree` and
|
|
162
162
|
`IndexOfMaxValSegmentTree` for examples.
|
|
163
163
|
|
|
164
|
-
Since there are several concrete "types" and two underlying generic
|
|
164
|
+
Since there are several concrete "types" and two underlying generic implementations there is a convenience method on the `SegmentTree`
|
|
165
165
|
module to get instances.
|
|
166
166
|
|
|
167
167
|
``` ruby
|
|
@@ -173,7 +173,7 @@ data = [1, -3, 2, 1, 5, -9]
|
|
|
173
173
|
# Get a segment tree instance that will answer "max over this subinterval?" questions about data.
|
|
174
174
|
# Here we get one using the ruby implementation of the generic functionality.
|
|
175
175
|
#
|
|
176
|
-
# Put :index_of_max in place of :
|
|
176
|
+
# Put :index_of_max in place of :max to get an instance that returns "an index of the maximum value
|
|
177
177
|
# over this subinterval".
|
|
178
178
|
#
|
|
179
179
|
# To use the generic code written in C, put :c instead of :ruby.
|
|
@@ -195,6 +195,10 @@ The Algorithms submodule contains some algorithms using the data structures.
|
|
|
195
195
|
[left, right, bottom, top].
|
|
196
196
|
- The algorithm is due to [[DMNS2013]](#references).
|
|
197
197
|
|
|
198
|
+
- `first_k(enumerable, k)
|
|
199
|
+
- Given an enumerable, return the first k elements in sorted order. That is, return the first k (smallest) elements of the sorted
|
|
200
|
+
version of the enumerable. We use a heap. Run time is O(n log k), where n is the size of the enumerable.
|
|
201
|
+
|
|
198
202
|
# C Extensions
|
|
199
203
|
|
|
200
204
|
As another learning process I have implemented several of these data structures as C extensions. The APIs are the same.
|
|
@@ -218,7 +222,7 @@ I'm a bit suprised the improvement isn't larger, but remember that the C code mu
|
|
|
218
222
|
in the underlying data array, and must access and combine them via Ruby lambdas.
|
|
219
223
|
|
|
220
224
|
# References
|
|
221
|
-
- [Allan] Allan, J., _CC: Convenient Containers_, https://github.com/JacksonAllan/CC, (retrieved
|
|
225
|
+
- [Allan] Allan, J., _CC: Convenient Containers_, https://github.com/JacksonAllan/CC, (retrieved 2024-12-04).
|
|
222
226
|
- [TvL1984] Tarjan, Robert E., van Leeuwen, J., _Worst-case Analysis of Set Union Algorithms_, Journal of the ACM, v31:2 (1984), pp
|
|
223
227
|
245–281, https://dl.acm.org/doi/10.1145/62.2160 (retrieved 2022-02-01).
|
|
224
228
|
- [EEK2017] Edelkamp, S., Elmasry, A., Katajainen, J., _Optimizing Binary Heaps_, Theory Comput Syst (2017), vol 61, pp 606-636, DOI
|