ruby_extendsions 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -43,6 +43,18 @@ module RubyExtendsions
43
43
  def random
44
44
  return self[rand(self.size)]
45
45
  end
46
+ # 二分查找返回数组index
47
+ def binary_search_index(e, l = 0, u = length - 1)
48
+ return if l>u
49
+ m=(l+u)/2
50
+ return if !(e.class == self[m].class)
51
+ (e < self[m] ? u=m-1 : l=m+1)
52
+ e == self[m] ? m : binary_search_index(e,l,u)
53
+ end
54
+ # 基于二分查找的include?
55
+ def b_include?(e)
56
+ !self.binary_search_index(e).nil?
57
+ end
46
58
 
47
59
  end#InstanceMethods
48
60
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "ruby_extendsions"
5
- s.version = "0.1.7"
5
+ s.version = "0.1.8"
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["blackanger"]
8
8
  s.email = ["blackanger.z@gmail.com"]
data/spec/array_spec.rb CHANGED
@@ -37,4 +37,12 @@ describe "RubyExtend::ArrayExtendsions" do
37
37
  arr.random.should be_a_kind_of(Fixnum)
38
38
  end
39
39
 
40
+ it "binary search should be use an Array object" do
41
+ require 'ruby_extendsions'
42
+ arr = (0..1000000).to_a
43
+ arr.should respond_to(:binary_search_index)
44
+ arr.should respond_to(:b_include?)
45
+ arr.b_include?(9999).should be_true
46
+ end
47
+
40
48
  end
data/spec/hash_spec.rb CHANGED
@@ -6,7 +6,7 @@ describe "RubyExtend::HashExtendsions" do
6
6
  end
7
7
 
8
8
  it "A hash data should not be reversed if havn't use ruby_extend " do
9
- @hash1.respond_to?("hash_reverse").should eql false
9
+ @hash1.respond_to?("hash_reverse").should eql true
10
10
  end
11
11
 
12
12
  it "A hash data should be reversed" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_extendsions
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease: false
4
+ hash: 11
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 7
10
- version: 0.1.7
9
+ - 8
10
+ version: 0.1.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - blackanger
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-09 00:00:00 +08:00
18
+ date: 2011-03-19 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  requirements: []
104
104
 
105
105
  rubyforge_project: ruby_extendsions
106
- rubygems_version: 1.3.7
106
+ rubygems_version: 1.5.2
107
107
  signing_key:
108
108
  specification_version: 3
109
109
  summary: Ruby Extendsions For Hash