bise 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.rdoc +1 -1
  2. data/Rakefile +4 -0
  3. data/lib/bise/version.rb +1 -1
  4. metadata +14 -7
  5. data/gem +0 -84
@@ -1,5 +1,5 @@
1
1
  = Bise
2
- Binary search for presorted text files. Finds the first occurance of a string
2
+ Binary search for presorted text files. Gem adds #bin_find(term) method to File. It finds the first occurance of a string
3
3
  with value >= provided term.
4
4
 
5
5
  Finds the first string in the oredered file that satisfies term <= str.
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new('spec')
4
+
5
+ task :default => :spec
@@ -1,3 +1,3 @@
1
1
  module Bise
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-28 00:00:00.000000000Z
12
+ date: 2013-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70027100 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,12 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70027100
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  description: Binary search in ordered text files
26
31
  email:
27
32
  - rubify@softover.com
@@ -35,7 +40,6 @@ files:
35
40
  - README.rdoc
36
41
  - Rakefile
37
42
  - bise.gemspec
38
- - gem
39
43
  - lib/bise.rb
40
44
  - lib/bise/version.rb
41
45
  - spec/bise_spec.rb
@@ -61,8 +65,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
65
  version: '0'
62
66
  requirements: []
63
67
  rubyforge_project: bise
64
- rubygems_version: 1.8.11
68
+ rubygems_version: 1.8.24
65
69
  signing_key:
66
70
  specification_version: 3
67
71
  summary: Binary search in text files
68
- test_files: []
72
+ test_files:
73
+ - spec/bise_spec.rb
74
+ - spec/dict
75
+ - spec/spec_helper.rb
data/gem DELETED
@@ -1,84 +0,0 @@
1
- module BinarySearch
2
- def bin_find(term)
3
- if block_given?
4
- compare = lambda { |a, b| yield(a, b) }
5
- else
6
- compare = lambda { |a, b| a <=> b }
7
- end
8
- bin_search(term, 0, stat.size, &compare)
9
- end
10
-
11
- private
12
-
13
- def bin_search(term, start, finish, &block)
14
- pos = (start + finish + 1) / 2
15
- seek pos
16
- gets unless pos == 0
17
- str = gets
18
- return str if start >= finish
19
- return nil unless str
20
- comp = yield(term, str)
21
- case comp
22
- when 1
23
- bin_search(term, pos, finish, &block)
24
- when -1
25
- pos == finish ? str : bin_search(term, start, pos, &block)
26
- else
27
- str
28
- end
29
- end
30
- end
31
-
32
- class File < IO
33
- include BinarySearch
34
- end
35
-
36
-
37
- #nums=[]
38
- #out=true
39
- #max = (4294967295 - 50331648) + 50331647
40
- #if ARGV[0] == '-test'
41
- # n=ARGV[1].to_i
42
- # n.times{ nums << rand( max + 1 )}
43
- # out=false
44
- #else
45
- # ARGV.each do |argv|
46
- # nums << argv.to_i #((($1.to_i*256)+$2.to_i)*256+$3.to_i)*256+$4.to_i if argv=~/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/
47
- # end
48
- #end
49
- #if nums.empty?
50
- # puts "Please enter valid ip(s)"
51
- # exit
52
- #end
53
- #
54
- #nums.each do |num|
55
- # ctry='Unknown'
56
- # res=bin_find('../files/IpToCountry.csv',num) { |search, str|
57
- # res = nil
58
- # if str.empty? || str[0,1]!='"'
59
- # res = 1
60
- # else
61
- # l, r = str.gsub('"','').split(',')[0,2].map(&:to_i)
62
- # if (l..r) === search
63
- # res = 0
64
- # else
65
- # res = search > r ? 1 : -1
66
- # end
67
- # res
68
- # end
69
- # }.gsub('"','').split(',')
70
- # ctry=res[4] if (res[0].to_i..res[1].to_i)===num
71
- # puts ctry if out
72
- #end
73
-
74
- itc_compare = lambda do |num, str|
75
- return 1 if str.empty? || str[0] != '"'
76
- l, r = str.gsub('"','').split(',')[0,2].map(&:to_i)
77
- return 0 if (l..r) === num
78
- num > r ? 1 : -1
79
- end
80
-
81
- num = (($1.to_i << 8 | $2.to_i) << 8 | $3.to_i ) << 8 | $4.to_i if ARGV[0]=~/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/
82
- puts File.open('/usr/share/dict/words'){|f| f.bin_find(ARGV[0])}
83
- puts File.open('../files/IpToCountry.csv'){|f| f.bin_find(num, &itc_compare}
84
-