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 +4 -4
- data/README.md +28 -0
- data/lib/Heap/binary_heap/binary_heap_max.rb +9 -2
- data/lib/Heap/binary_heap/binary_heap_min.rb +9 -2
- data/lib/Heap/version.rb +1 -1
- data/ruby-heap-0.2.0.gem +0 -0
- metadata +3 -3
- data/ruby-heap-0.1.0.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bd6fb0a7c6e5b0d84fdfea7abac405037ce91c5
|
4
|
+
data.tar.gz: f09eb9984b43ff08022eb8ae14b4c4b520f3cbdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
13
|
-
|
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
|
-
|
13
|
-
|
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
|
data/lib/Heap/version.rb
CHANGED
data/ruby-heap-0.2.0.gem
ADDED
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.
|
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-
|
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.
|
75
|
+
- ruby-heap-0.2.0.gem
|
76
76
|
homepage: https://github.com/pups3s/ruby-heap
|
77
77
|
licenses:
|
78
78
|
- MIT
|
data/ruby-heap-0.1.0.gem
DELETED
Binary file
|