china_ad_ip 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/china_ad_ip.gemspec +1 -1
- data/lib/.DS_Store +0 -0
- data/lib/china_ad_ip.rb +29 -12
- data/lib/china_ad_ip/version.rb +1 -1
- data/lib/libbinarysearch.so +0 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f93ae8ff8e2025522fb7b4ab01ca88284b6b78b
|
4
|
+
data.tar.gz: 39e883203a646deb706077d5035a3aa8e0507ef6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 537a6704a6deeb63a2ae4fed3fa911991f0caea259553dfaac00948ca9765b8acb4f9c73f56b2ec048bc6cb1eff83b2d2a0c9babd68fcec86ab6054f2ebe4078
|
7
|
+
data.tar.gz: 76811430031222e2f64c086b76bf747cdcb03268009634ff23357acda96ac8b0728392e1f50df6ae981240446c0f04a9f858cd88cdc909c19d55595b3d4fd592
|
data/.gitignore
CHANGED
data/china_ad_ip.gemspec
CHANGED
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/china_ad_ip.rb
CHANGED
@@ -1,12 +1,34 @@
|
|
1
1
|
require "china_ad_ip/version"
|
2
2
|
require 'china_ad_ip/ipv4'
|
3
3
|
require 'csv'
|
4
|
+
require 'ffi'
|
4
5
|
|
5
6
|
module ChinaAdIp
|
6
7
|
NAME = "ChinaAdIp"
|
7
8
|
GEM = "china_ad_ip"
|
8
9
|
AUTHORS = ["suezhen <sz3001@gmail.com>"]
|
9
10
|
|
11
|
+
extend FFI::Library
|
12
|
+
ffi_lib "libbinarysearch.so"
|
13
|
+
attach_function :binarysearch, [:pointer,:long,:long], :long
|
14
|
+
|
15
|
+
|
16
|
+
module LibC
|
17
|
+
extend FFI::Library
|
18
|
+
ffi_lib FFI::Library::LIBC
|
19
|
+
|
20
|
+
# memory allocators
|
21
|
+
attach_function :malloc, [:size_t], :pointer
|
22
|
+
attach_function :calloc, [:size_t], :pointer
|
23
|
+
attach_function :valloc, [:size_t], :pointer
|
24
|
+
attach_function :realloc, [:pointer, :size_t], :pointer
|
25
|
+
attach_function :free, [:pointer], :void
|
26
|
+
|
27
|
+
# memory movers
|
28
|
+
attach_function :memcpy, [:pointer, :pointer, :size_t], :pointer
|
29
|
+
attach_function :bcopy, [:pointer, :pointer, :size_t], :void
|
30
|
+
|
31
|
+
end # module LibC
|
10
32
|
|
11
33
|
def self.ntoa(uint)
|
12
34
|
unless(uint.is_a? Numeric and uint <= 0xffffffff and uint >= 0)
|
@@ -64,9 +86,7 @@ module ChinaAdIp
|
|
64
86
|
ip_addr = ChinaAdIp::IPv4.new(addr)
|
65
87
|
|
66
88
|
if $ip_sections && $locations
|
67
|
-
|
68
|
-
index = dichotomy(ip_addr.to_i,$ip_sections.collect{|ip_section| ip_section[0]}.to_a)
|
69
|
-
|
89
|
+
index = ChinaAdIp.binarysearch(self.arr_pointer,ip_addr.to_i,ip_arr.length)
|
70
90
|
$locations[$ip_sections[index][2]]
|
71
91
|
else
|
72
92
|
raise(::ArgumentError, "not exists csv data")
|
@@ -75,16 +95,13 @@ module ChinaAdIp
|
|
75
95
|
end
|
76
96
|
|
77
97
|
|
78
|
-
def self.
|
79
|
-
|
80
|
-
while(true)
|
81
|
-
index = start_index + ((end_index - start_index) / 2)
|
82
|
-
start_index = index if array[index] < search
|
83
|
-
end_index = index if array[index] > search
|
84
|
-
break if array[index] == search || ((start_index == index) && (start_index+1 == end_index))
|
85
|
-
end
|
86
|
-
index
|
98
|
+
def self.ip_arr
|
99
|
+
@@ip_arr ||= $ip_sections.collect{|ip_section| ip_section[0]}.to_a
|
87
100
|
end
|
88
101
|
|
102
|
+
def self.arr_pointer
|
103
|
+
buffer = LibC.malloc(ip_arr.first.size * ip_arr.size)
|
104
|
+
buffer.write_array_of_long ip_arr
|
105
|
+
end
|
89
106
|
|
90
107
|
end
|
data/lib/china_ad_ip/version.rb
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: china_ad_ip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- suezhen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ffi
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: 'locate ip '
|
42
56
|
email:
|
43
57
|
- sz3001@gmail.com
|
@@ -51,9 +65,11 @@ files:
|
|
51
65
|
- README.md
|
52
66
|
- Rakefile
|
53
67
|
- china_ad_ip.gemspec
|
68
|
+
- lib/.DS_Store
|
54
69
|
- lib/china_ad_ip.rb
|
55
70
|
- lib/china_ad_ip/ipv4.rb
|
56
71
|
- lib/china_ad_ip/version.rb
|
72
|
+
- lib/libbinarysearch.so
|
57
73
|
homepage: https://github.com/suzhen/china_ad_ip
|
58
74
|
licenses:
|
59
75
|
- MIT
|