data_structures_rmolinari 0.5.6 → 0.5.7
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 +3 -2
- data/lib/data_structures_rmolinari/heap.rb +7 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02563eb882aace27085e0db092d5a266c413c1864fe3c74d23d9c2af194f2d87
|
4
|
+
data.tar.gz: 2153f481d92569fbee02caea9df2177d9f7465d18e39d3764c4e92fc65a7cae6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbe47a34b03026dd0f82e5a3ba75a31c2a24a03b1d4d32fe94c0b9760e53c9171a964bec7fa04a7cc675bd980c938781c75e4f09817f4cac6b866f1aebf2483a
|
7
|
+
data.tar.gz: 9a80a2984dd8ed2caa63393b0a363c3e3e7414a79217bbb5daf1015a9c17b0842ff534d366eef05adb311ed7ef889a171140af282e3aee71619be3d9483e93c7
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -53,12 +53,13 @@ operations:
|
|
53
53
|
|
54
54
|
- `insert(item, priority)`, insert the given item with the stated priority.
|
55
55
|
- By default, items must be distinct.
|
56
|
-
- `top`,
|
56
|
+
- `top`, return the element with smallest priority
|
57
|
+
- `top_priority`, return the _priority_ of the top element
|
57
58
|
- `pop`, return the element with smallest priority and remove it from the structure
|
58
59
|
- `update(item, priority)`, update the priority of the given item, which must already be in the heap
|
59
60
|
- `update_by_delta(item, delta)`, update the priorityof the given item by adding delta to the priority; the item must already be in the heap
|
60
61
|
|
61
|
-
`top`
|
62
|
+
`top` and `top_priority` are O(1). The others are O(log n) where n is the number of items in the heap.
|
62
63
|
|
63
64
|
By default we have a min-heap: the top element is the one with smallest priority. A configuration parameter at construction can make
|
64
65
|
it a max-heap.
|
@@ -101,6 +101,13 @@ class DataStructuresRMolinari::Heap
|
|
101
101
|
@data[root].item
|
102
102
|
end
|
103
103
|
|
104
|
+
# Return the priority of the item at the top of the heap
|
105
|
+
def top_priority
|
106
|
+
raise 'Heap is empty!' unless @size.positive?
|
107
|
+
|
108
|
+
@data[root].priority
|
109
|
+
end
|
110
|
+
|
104
111
|
# Return the top of the heap and remove it, updating the structure to maintain the necessary properties.
|
105
112
|
# @return (see #top)
|
106
113
|
def pop
|