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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1fbafd7af3c7bd2d1eee3303fd8b8a759b0d67fc29bfdca3b7f67b626e9fe175
4
- data.tar.gz: 5a870554e38c61b1e1af64d2205bc002cf7cb731e5412606543ffdce014342b4
3
+ metadata.gz: 02563eb882aace27085e0db092d5a266c413c1864fe3c74d23d9c2af194f2d87
4
+ data.tar.gz: 2153f481d92569fbee02caea9df2177d9f7465d18e39d3764c4e92fc65a7cae6
5
5
  SHA512:
6
- metadata.gz: fcdaae719324c5b8b7914eb6a982563d58ee10170d52280c58429e8d9b5a7e5224079350ab15ad618b5cacbcdf340c17feec2b34616e17847d5b0e16a7569d50
7
- data.tar.gz: 446e2190ff33f65c9cb6cedd6043af506aa6f395f279e54520b2ba1c0c04fbd8504615f1a94e09232edefee9b0cb0d55363aa20b6504467d70f6766b19698464
6
+ metadata.gz: dbe47a34b03026dd0f82e5a3ba75a31c2a24a03b1d4d32fe94c0b9760e53c9171a964bec7fa04a7cc675bd980c938781c75e4f09817f4cac6b866f1aebf2483a
7
+ data.tar.gz: 9a80a2984dd8ed2caa63393b0a363c3e3e7414a79217bbb5daf1015a9c17b0842ff534d366eef05adb311ed7ef889a171140af282e3aee71619be3d9483e93c7
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.5.7] 2024-01-04
6
+
7
+ - Heap
8
+ - addd top_priority method
9
+
5
10
  ## [0.5.6] 2024-01-04
6
11
 
7
12
  - Heap
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`, returning the element with smallest priority
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` is O(1). The others are O(log n) where n is the number of items in the heap.
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_structures_rmolinari
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rory Molinari