ruby_extendsions 0.1.8.2 → 0.1.8.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -44,25 +44,32 @@ module RubyExtendsions
44
44
  def random
45
45
  return self[rand(self.size)]
46
46
  end
47
- # 二分查找返回数组index
47
+ # 二分查找返回数组index, 只限于可排序的元素
48
48
  def binary_search_index(e, l = 0, u = length - 1)
49
49
  return if l>u
50
50
  m=(l+u)/2
51
51
  return if !(e.class == self[m].class)
52
- e < self[m] ? u=m-1 : l=m+1
53
- e == self[m] ? m : binary_search_index(e,l,u)
52
+ begin
53
+ e < self[m] ? u=m-1 : l=m+1
54
+ e == self[m] ? m : binary_search_index(e,l,u)
55
+ rescue
56
+ return nil
57
+ end
54
58
  end
55
59
 
56
60
  # 基于二分查找的include?
57
61
  def b_include? e
58
- !self.binary_search_index(e).nil?
62
+ begin
63
+ temp = self.sort
64
+ !temp.binary_search_index(e).nil?
65
+ rescue
66
+ return false
67
+ end
59
68
  end
60
69
 
61
- #比较两个数组内容相同
70
+ #比较两个数组内容相同,不包含顺序
62
71
  def compare_content com_arr
63
- arr = Set.new self
64
- com_arr = Set.new com_arr
65
- return arr == com_arr
72
+ Set.new(self) == Set.new(com_arr)
66
73
  end
67
74
 
68
75
  end#InstanceMethods
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "ruby_extendsions"
5
- s.version = "0.1.8.2"
5
+ s.version = "0.1.8.3"
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["blackanger"]
8
8
  s.email = ["blackanger.z@gmail.com"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_extendsions
3
3
  version: !ruby/object:Gem::Version
4
- hash: 99
4
+ hash: 97
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
9
  - 8
10
- - 2
11
- version: 0.1.8.2
10
+ - 3
11
+ version: 0.1.8.3
12
12
  platform: ruby
13
13
  authors:
14
14
  - blackanger
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-03-19 00:00:00 +08:00
19
+ date: 2011-03-20 00:00:00 +08:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency