ruborithms 0.1.0 → 0.2.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 +4 -4
- data/lib/ruborithms/algorithms/binary_search.rb +33 -0
- data/lib/ruborithms/algorithms/linear_search.rb +0 -1
- data/lib/ruborithms/version.rb +1 -1
- data/lib/ruborithms.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10cd7489ede0df5657b5f23b120d4320fffe8f2e
|
4
|
+
data.tar.gz: 7f820dbf794f9422e343258e988f630661c3e0c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b915c0b6d49580899bb594c644bdbd939299101b535f691f510654daf8e513caa0d8ac01aaad880a7b379ce0049f5c272dfff7f84b61bfbb9f54cc548d977c7e
|
7
|
+
data.tar.gz: bdb98ed962a3a6712cec578d224fb06ed5721a5f01ac34e00ac769465a67301077add14f112827468b6a54382c22e23521235fae5f9752c29d1ee9c5cdeb3c1d
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Ruborithms
|
2
|
+
module Algorithms
|
3
|
+
module BinarySearch
|
4
|
+
class << self
|
5
|
+
def included(mod)
|
6
|
+
mod.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def binary_search(object, value)
|
12
|
+
min = 0
|
13
|
+
max = object.count - 1
|
14
|
+
while (max >= min)
|
15
|
+
avg = ((max + min) / 2).floor
|
16
|
+
if object[avg] == value
|
17
|
+
return avg
|
18
|
+
elsif object[avg] > value
|
19
|
+
max = avg - 1
|
20
|
+
else
|
21
|
+
min = avg + 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def binary_search(value)
|
29
|
+
self.class.binary_search(self, value)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/ruborithms/version.rb
CHANGED
data/lib/ruborithms.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruborithms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Zinovyev
|
@@ -32,6 +32,7 @@ extra_rdoc_files: []
|
|
32
32
|
files:
|
33
33
|
- ".gitignore"
|
34
34
|
- lib/ruborithms.rb
|
35
|
+
- lib/ruborithms/algorithms/binary_search.rb
|
35
36
|
- lib/ruborithms/algorithms/linear_search.rb
|
36
37
|
- lib/ruborithms/version.rb
|
37
38
|
homepage: https://github.com/zinovyev/ruborithms
|