ruby-heap 0.2.0 → 0.2.1

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
  SHA1:
3
- metadata.gz: 67185670438a9077e5eec874db91d471ce687900
4
- data.tar.gz: efbfb03e0365fbff555a2e94b7d2c6873a6d3515
3
+ metadata.gz: 6bd6fb0a7c6e5b0d84fdfea7abac405037ce91c5
4
+ data.tar.gz: f09eb9984b43ff08022eb8ae14b4c4b520f3cbdf
5
5
  SHA512:
6
- metadata.gz: 842e05fb7274881285c6a090c1e4abf03275c78544d9d52515d13e0a6e7eddc8b0d9622228b9f184a136668aaff5e8b14196912554979ef0f9579d09946b7ad1
7
- data.tar.gz: 11d8a860de8756728694120d5d3bdf53c232764656505a929a7f74514b09c879242733fcd534ef2cd709cd3e7fd1809f8a01ee5614d4e6d1fb1515896b5ebafb
6
+ metadata.gz: 60756e904112268823c46d170d57726e54b60f7b2337277ad25ebb255f90d63cae23a89e92e15ca855edc00100a257f506822ea7a19ebf37e5a18b911ec63838
7
+ data.tar.gz: 6d35f22ea327f8cee99a8fa9a3f2ed6878d3709970fe0b007319a3b2479391065c3b209b1e3bed77291f491ffc36281833bad5946c1905c6242b99fc2b6e7d79
data/README.md CHANGED
@@ -21,6 +21,8 @@ Or install it yourself as:
21
21
  ## Usage
22
22
 
23
23
  #### Binary Heap with min root
24
+ While Heap initialize you can add any comparable object in it (not numbers only).
25
+ Objects must have compare functions (>, >=, <, <=).
24
26
  ```ruby
25
27
  require 'Heap'
26
28
 
@@ -46,6 +48,32 @@ b_heap.count # 3
46
48
  b_heap.elements # [1, 2, 3]
47
49
  ```
48
50
 
51
+ #### Same practice with max root
52
+ ```ruby
53
+ require 'Heap'
54
+
55
+ # Initialize
56
+ b_heap = Heap::BinaryHeap::MaxHeap.new([2, 3, 1, -1])
57
+
58
+ # Return elements in Heap (read access only)
59
+ b_heap.elements # [3, 2, 1, -1]
60
+
61
+ # Return sorted array (heap-sort) without
62
+ # changing elements in heap
63
+ b_heap.sort # [3, 2, 1, -1]
64
+
65
+ # Count of elements in Heap
66
+ b_heap.count # 4
67
+
68
+ # Return min element without removing from Heap
69
+ b_heap.extract_max # 3
70
+
71
+ # Return min element and remove it from Heap
72
+ b_heap.extract_max! # 3
73
+ b_heap.count # 3
74
+ b_heap.elements # [2, -1, 1]
75
+ ```
76
+
49
77
  ## Development
50
78
 
51
79
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -9,8 +9,15 @@ module Heap
9
9
  end
10
10
 
11
11
  def add(element)
12
- @elements.push element
13
- swim_up(count)
12
+ if element.is_a? Array
13
+ element.each do |el|
14
+ @elements.push el
15
+ swim_up(count)
16
+ end
17
+ else
18
+ @elements.push element
19
+ swim_up(count)
20
+ end
14
21
  end
15
22
 
16
23
  def count
@@ -9,8 +9,15 @@ module Heap
9
9
  end
10
10
 
11
11
  def add(element)
12
- @elements.push element
13
- swim_up(count)
12
+ if element.is_a? Array
13
+ element.each do |el|
14
+ @elements.push el
15
+ swim_up(count)
16
+ end
17
+ else
18
+ @elements.push element
19
+ swim_up(count)
20
+ end
14
21
  end
15
22
 
16
23
  def count
@@ -1,3 +1,3 @@
1
1
  module Heap
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-heap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandr Sysoev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-13 00:00:00.000000000 Z
11
+ date: 2017-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,7 +72,7 @@ files:
72
72
  - lib/Heap/binary_heap/binary_heap_max.rb
73
73
  - lib/Heap/binary_heap/binary_heap_min.rb
74
74
  - lib/Heap/version.rb
75
- - ruby-heap-0.1.0.gem
75
+ - ruby-heap-0.2.0.gem
76
76
  homepage: https://github.com/pups3s/ruby-heap
77
77
  licenses:
78
78
  - MIT
Binary file