algorithmable 0.7.0 → 0.8.0

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: 2ae7569f2df39cfefa86f0a46fafd1e1b91199d3
4
- data.tar.gz: ebb4364c7e699846eef95bd47e09c26b8dc721f2
3
+ metadata.gz: 210c9d66c15c6f091c2db2be2063d72db3243051
4
+ data.tar.gz: fba5ab243cfe9ce27ae93834b16ffb4500f6bcf3
5
5
  SHA512:
6
- metadata.gz: 7cae4039f94a406279f630ece5f363e05f9dd9c406152e9b19fdcf8adedf427a9ad8c21a569ba14a44f0e909c1980249e7d907b25e592c8129db10135f9797b8
7
- data.tar.gz: e2827ed66df194ee618724277b55c986c371dd8cd638632ccff264b3a81bb3853c1aa935cf7811ade5fa20aee47c65cbf2060d5a79c215d288f469fd322e4108
6
+ metadata.gz: 7dcddf1680bf74c69b2901e5867d3f2b1c7ff774b5386ed5c59dcc8449d6cc9a52f36478ad3876141fee89e541c2fb71b138ebcf6079ca8d2126f31e4a02050a
7
+ data.tar.gz: 5fb2fffdacf63cd41aff9436bce9226f8672139e23e01df6bcc3f580914ec204289d99c1ad94610a0d1b9288bf4a0f621dc547d060c462e9943d7c88b5c22be3
@@ -0,0 +1,26 @@
1
+ module Algorithmable
2
+ module Search
3
+ class Binary
4
+ def self.lookup(element, in_collection)
5
+ new.lookup(element, in_collection)
6
+ end
7
+
8
+ def lookup(element, collection)
9
+ traverse element, collection, 0, collection.length - 1
10
+ end
11
+
12
+ def traverse(element, collection, low, high)
13
+ while low <= high
14
+ mid = low + (high - low) / 2
15
+ if element < collection[mid]
16
+ high = mid.pred
17
+ elsif element > collection[mid]
18
+ low = mid.next
19
+ else
20
+ return mid
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ module Algorithmable
2
+ module Search
3
+ autoload :Binary, 'algorithmable/search/binary'
4
+
5
+ class << self
6
+ def binary(element, collection)
7
+ Binary.index_of(element, collection)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Algorithmable
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.0'
3
3
  end
data/lib/algorithmable.rb CHANGED
@@ -7,6 +7,7 @@ require 'English'
7
7
  module Algorithmable
8
8
  autoload :Errors, 'algorithmable/errors'
9
9
  autoload :Sort, 'algorithmable/sort'
10
+ autoload :Search, 'algorithmable/search'
10
11
  autoload :DataStructs, 'algorithmable/data_structs'
11
12
  autoload :Graphs, 'algorithmable/graphs'
12
13
  autoload :Puzzles, 'algorithmable/puzzles'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algorithmable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Lishtaba
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-07 00:00:00.000000000 Z
11
+ date: 2016-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -156,6 +156,8 @@ files:
156
156
  - lib/algorithmable/puzzles.rb
157
157
  - lib/algorithmable/puzzles/dijkstras_two_stacks.rb
158
158
  - lib/algorithmable/puzzles/josephus_problem.rb
159
+ - lib/algorithmable/search.rb
160
+ - lib/algorithmable/search/binary.rb
159
161
  - lib/algorithmable/sort.rb
160
162
  - lib/algorithmable/sort/binary_heap.rb
161
163
  - lib/algorithmable/sort/bubble.rb