ipaddr_list 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +33 -2
- data/Rakefile +1 -1
- data/lib/ipaddr_list.rb +8 -3
- data/spec/ipaddr_list_spec.rb +23 -0
- metadata +1 -1
data/ChangeLog
CHANGED
@@ -1,4 +1,35 @@
|
|
1
|
-
|
1
|
+
commit 0c9a5e72de5b4cb1739e93964448318be4facf8b
|
2
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
3
|
+
Date: Sat Sep 13 06:52:05 2008 +0900
|
2
4
|
|
3
|
-
|
5
|
+
added documentation.
|
4
6
|
|
7
|
+
commit 95f2be45d872dc2222982cd4953b88c733405842
|
8
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
9
|
+
Date: Sat Sep 13 06:51:47 2008 +0900
|
10
|
+
|
11
|
+
added development_dependency.
|
12
|
+
|
13
|
+
commit 92e40373def8978b74f87ef5ce80e215a445edb6
|
14
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
15
|
+
Date: Sat Sep 13 06:34:19 2008 +0900
|
16
|
+
|
17
|
+
fixed warnings.
|
18
|
+
|
19
|
+
commit 6b144d023d387993daa4ad7db3f2945c55a4a590
|
20
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
21
|
+
Date: Fri Sep 5 09:17:58 2008 +0900
|
22
|
+
|
23
|
+
added algorithm Linear search.
|
24
|
+
|
25
|
+
commit 9143d6eea71c652cb4bd6d9869f3c876aeebcfd0
|
26
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
27
|
+
Date: Fri Sep 5 09:16:29 2008 +0900
|
28
|
+
|
29
|
+
added benchmark.
|
30
|
+
|
31
|
+
commit 3474ddd98bbaa710a10d020c66fa0b0b3a040a47
|
32
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
33
|
+
Date: Fri Sep 5 01:36:37 2008 +0900
|
34
|
+
|
35
|
+
initial import.
|
data/Rakefile
CHANGED
data/lib/ipaddr_list.rb
CHANGED
@@ -134,12 +134,17 @@ class IPAddrList
|
|
134
134
|
# binary search
|
135
135
|
# SEE ALSO: http://dsas.blog.klab.org/archives/51293334.html
|
136
136
|
def binary_search ip, &block
|
137
|
-
ipaddr =
|
137
|
+
ipaddr = nil
|
138
|
+
if ip.kind_of? IPAddr
|
139
|
+
ipaddr = ip
|
140
|
+
else
|
141
|
+
ipaddr = IPAddr.new(ip)
|
142
|
+
end
|
138
143
|
min_idx = 0
|
139
144
|
max_idx = @ip_list.size - 1
|
140
|
-
if @ip_list[max_idx]
|
145
|
+
if @ip_list[max_idx] < ipaddr
|
141
146
|
min_idx = max_idx
|
142
|
-
elsif @ip_list[min_idx]
|
147
|
+
elsif @ip_list[min_idx] > ipaddr
|
143
148
|
max_idx = min_idx
|
144
149
|
else
|
145
150
|
span = max_idx - min_idx
|
data/spec/ipaddr_list_spec.rb
CHANGED
@@ -2,4 +2,27 @@ require File.join(File.dirname(__FILE__), 'spec_helper')
|
|
2
2
|
require 'ipaddr_list'
|
3
3
|
|
4
4
|
describe IPAddrList do
|
5
|
+
before do
|
6
|
+
@ipaddr_list = %w( 192.168.0.1 127.0.0.1 )
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should include? in :BinarySearch' do
|
10
|
+
ipaddr_list = IPAddrList.new(@ipaddr_list, :BinarySearch)
|
11
|
+
ipaddr_list.should include('127.0.0.1')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should not include? in :BinarySearch' do
|
15
|
+
ipaddr_list = IPAddrList.new(@ipaddr_list, :BinarySearch)
|
16
|
+
ipaddr_list.should_not include('192.168.1.1')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should include? in :LinearSearch' do
|
20
|
+
ipaddr_list = IPAddrList.new(@ipaddr_list, :LinearSearch)
|
21
|
+
ipaddr_list.should include('127.0.0.1')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should include? in :LinearSearch' do
|
25
|
+
ipaddr_list = IPAddrList.new(@ipaddr_list, :LinearSearch)
|
26
|
+
ipaddr_list.should_not include('192.168.1.1')
|
27
|
+
end
|
5
28
|
end
|