ruby-heap 0.2.1 → 0.2.2

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: 6bd6fb0a7c6e5b0d84fdfea7abac405037ce91c5
4
- data.tar.gz: f09eb9984b43ff08022eb8ae14b4c4b520f3cbdf
3
+ metadata.gz: c9974abcd60bd8451a0b255d5a92a5662f017643
4
+ data.tar.gz: 619d3a2efe5beb55f18451dfef513a55deb10255
5
5
  SHA512:
6
- metadata.gz: 60756e904112268823c46d170d57726e54b60f7b2337277ad25ebb255f90d63cae23a89e92e15ca855edc00100a257f506822ea7a19ebf37e5a18b911ec63838
7
- data.tar.gz: 6d35f22ea327f8cee99a8fa9a3f2ed6878d3709970fe0b007319a3b2479391065c3b209b1e3bed77291f491ffc36281833bad5946c1905c6242b99fc2b6e7d79
6
+ metadata.gz: 0a49cc38bbdcb3d910ec6a80487bd6ff3fdbc7f9a5171d1a19e50db844702fa31b1320d78ab07f3496d0352c30ffe88f99829f655b01d24fefc57675b5a9e7e5
7
+ data.tar.gz: 3eb7d687cad878bf3d38bc7e373d21e8d6d132b5fa6604a2254aebc394874c4c48b1c554e2c78d6f590ed63f8e87d925d5022557448b345124f045c7d5311a1a
data/README.md CHANGED
@@ -46,6 +46,13 @@ b_heap.extract_min # -1
46
46
  b_heap.extract_min! # -1
47
47
  b_heap.count # 3
48
48
  b_heap.elements # [1, 2, 3]
49
+
50
+ # Also you can add elements with "add" function
51
+ b_heap.add -1
52
+ b_heap.elements # [-1, 1, 3, 2]
53
+ b_heap.add [0, 9, 200, -15, 6]
54
+ b_heap.elements # [-15, -1, 3, 0, 1, 9, 200, 2, 6]
55
+ b_heap.sort # [-15, -1, 0, 1, 2, 3, 6, 9, 200]
49
56
  ```
50
57
 
51
58
  #### Same practice with max root
@@ -72,6 +79,26 @@ b_heap.extract_max # 3
72
79
  b_heap.extract_max! # 3
73
80
  b_heap.count # 3
74
81
  b_heap.elements # [2, -1, 1]
82
+
83
+ # Also you can add elements with "add" function
84
+ b_heap.add -1
85
+ b_heap.elements # [2, -1, 1, -1]
86
+ b_heap.add [0, 9, 200, -15, 6]
87
+ b_heap.elements # [200, 6, 9, 0, -1, 1, 2, -15, -1]
88
+ b_heap.sort # [200, 9, 6, 2, 1, 0, -1, -1, -15]
89
+ ```
90
+
91
+ #### Heap merging
92
+ ```ruby
93
+ require 'Heap'
94
+
95
+ # Initialize heaps
96
+ min_heap = Heap::BinaryHeap::MinHeap.new [1, 2, 3]
97
+ max_heap = Heap::BinaryHeap::MaxHeap.new [9, -1, 4]
98
+
99
+ # Merge heaps
100
+ min_heap.add max_heap
101
+
75
102
  ```
76
103
 
77
104
  ## Development
@@ -14,6 +14,8 @@ module Heap
14
14
  @elements.push el
15
15
  swim_up(count)
16
16
  end
17
+ elsif defined? element.elements
18
+ add element.elements
17
19
  else
18
20
  @elements.push element
19
21
  swim_up(count)
@@ -14,6 +14,8 @@ module Heap
14
14
  @elements.push el
15
15
  swim_up(count)
16
16
  end
17
+ elsif defined? element.elements
18
+ add element.elements
17
19
  else
18
20
  @elements.push element
19
21
  swim_up(count)
@@ -1,3 +1,3 @@
1
1
  module Heap
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
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.1
4
+ version: 0.2.2
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-15 00:00:00.000000000 Z
11
+ date: 2017-06-19 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.2.0.gem
75
+ - ruby-heap-0.2.1.gem
76
76
  homepage: https://github.com/pups3s/ruby-heap
77
77
  licenses:
78
78
  - MIT
Binary file