ruborithms 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3cf3cbce1d2265a02d1f863a0c9a2f6e2f179fe0
4
- data.tar.gz: 5d940be77faed6cc6d725ef98a35146c4a3703de
3
+ metadata.gz: 10cd7489ede0df5657b5f23b120d4320fffe8f2e
4
+ data.tar.gz: 7f820dbf794f9422e343258e988f630661c3e0c8
5
5
  SHA512:
6
- metadata.gz: fa6295b1684b423516001f26d552cfab81effa7263a3ebccb3a5f395b67fc443b687a0f0f602ea3dfc132d6697cd08090afc70d14fa43ce20e29b05b32aab256
7
- data.tar.gz: 714c3d5bb38d872038b355ac52f5520e364eefc4227875c80ed7353e0f729afe3f45942d1603c69661a89232df54da5e1c0a72c61cd1c9c485bcac3e9d19ce3c
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
@@ -5,7 +5,6 @@ module Ruborithms
5
5
  def included(mod)
6
6
  mod.extend(ClassMethods)
7
7
  end
8
-
9
8
  end
10
9
 
11
10
  module ClassMethods
@@ -1,3 +1,3 @@
1
1
  module Ruborithms
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/ruborithms.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'ruborithms/version'
2
2
  require 'ruborithms/algorithms/linear_search'
3
+ require 'ruborithms/algorithms/binary_search'
3
4
 
4
5
  module Ruborithms
5
6
  end
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.1.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