algorithmable 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/algorithmable/search/binary.rb +26 -0
- data/lib/algorithmable/search.rb +11 -0
- data/lib/algorithmable/version.rb +1 -1
- data/lib/algorithmable.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 210c9d66c15c6f091c2db2be2063d72db3243051
|
4
|
+
data.tar.gz: fba5ab243cfe9ce27ae93834b16ffb4500f6bcf3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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.
|
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-
|
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
|