ruby_extendsions 0.1.8.2 → 0.1.8.3
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.
- data/lib/ruby_extendsions/array_extendsions.rb +15 -8
- data/ruby_extendsions.gemspec +1 -1
- metadata +4 -4
@@ -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
|
-
|
53
|
-
|
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
|
-
|
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
|
-
|
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
|
data/ruby_extendsions.gemspec
CHANGED
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:
|
4
|
+
hash: 97
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
9
|
- 8
|
10
|
-
-
|
11
|
-
version: 0.1.8.
|
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
|
+
date: 2011-03-20 00:00:00 +08:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|