lilutils 0.0.2 → 0.0.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/Gemfile +1 -1
- data/Gemfile.lock +0 -2
- data/History.txt +4 -0
- data/Manifest.txt +2 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/lilutils/algo_test_utils/data_sets.rb +1 -0
- data/lib/lilutils/misc/bit_vector.rb +52 -0
- data/lib/lilutils.rb +1 -1
- data/lilutils.gemspec +5 -5
- data/test/algo_test_utils/data_sets_test.rb +7 -0
- data/test/misc/bit_vector_test.rb +52 -0
- data/test/test_lilutils.rb +1 -0
- metadata +56 -62
data/Gemfile
CHANGED
@@ -6,7 +6,7 @@ source "http://rubygems.org"
|
|
6
6
|
# Add dependencies to develop your gem here.
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
group :development do
|
9
|
-
gem "shoulda", ">= 0"
|
9
|
+
# gem "shoulda", ">= 0"
|
10
10
|
gem "bundler", "~> 1.0.0"
|
11
11
|
gem "jeweler", "~> 1.5.2"
|
12
12
|
gem "rcov", ">= 0"
|
data/Gemfile.lock
CHANGED
data/History.txt
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
=== 0.0.3
|
2
|
+
* A Misc Utility to implement the classic bit vector.
|
3
|
+
* Fixed a bug in ascii_strings method where the seeding of the random number generator was just failing.
|
4
|
+
* Added a test to guard against the bug found
|
1
5
|
=== 0.0.2
|
2
6
|
* Utility to test whether an array is in order. The comparator is defined by the block.
|
3
7
|
* Utility to find out the sandwiching indexes for an element in a given collection that is supposed to be sorted.
|
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -13,7 +13,7 @@ require 'jeweler'
|
|
13
13
|
Jeweler::Tasks.new do |gem|
|
14
14
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
15
|
gem.name = "lilutils"
|
16
|
-
gem.version = "0.0.
|
16
|
+
gem.version = "0.0.3"
|
17
17
|
gem.homepage = "http://github.com/kedarmhaswade/lilutils"
|
18
18
|
gem.license = "MIT"
|
19
19
|
gem.summary = %Q{Little utilities for everyone}
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module LilUtils
|
2
|
+
module Misc
|
3
|
+
# Class to implement a bit vector that uses an array of Fixnums as its storage.
|
4
|
+
# Implements the basic bit vector operations as specified.
|
5
|
+
class BitVector
|
6
|
+
|
7
|
+
BITS_PER_ITEM = 0.size * 8
|
8
|
+
|
9
|
+
def initialize(size)
|
10
|
+
raise ArgumentError, "size must be positive" if size <= 0
|
11
|
+
@size = size
|
12
|
+
@array = Array.new((size*1.0/BITS_PER_ITEM).ceil) { |i| 0 } #=> array contains required # of Fixnums, initialized to zero
|
13
|
+
end
|
14
|
+
|
15
|
+
# Sets the 'i'th bit of this Bit Vector.
|
16
|
+
# @param [Fixnum] i Represents the index of given, must be from 0 to @size-1
|
17
|
+
# @raise [ArgumentError] if 0 < i <= n
|
18
|
+
# @return nothing
|
19
|
+
def set(i)
|
20
|
+
raise ArgumentError, "argument (#{i}) should be between 0 and #{@size}" if i < 0 or i >= @size
|
21
|
+
@array[get_index(i)] |= (1 << get_shift(i))
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
# Tests whether ith bit of this Bit Vector is set
|
26
|
+
# @param [Fixnum] i Represents the index of given bit, must be from 0 to @size-1
|
27
|
+
# @return [Fixnum] 1 if ith bit is set, 0 otherwise
|
28
|
+
def test(i)
|
29
|
+
raise ArgumentError, "argument (#{i}) should be between 0 and #{@size}" if i < 0 or i >= @size
|
30
|
+
(@array[get_index(i)] & (1 << (get_shift(i))))>>(get_shift(i))
|
31
|
+
end
|
32
|
+
|
33
|
+
# Clears the given bit (i.e. makes it 0).
|
34
|
+
# @param [Fixnum] i Represents the index of given bit, must be from 0 to @size-1
|
35
|
+
# @return nothing
|
36
|
+
def clear(i)
|
37
|
+
raise ArgumentError, "argument (#{i}) should be between 0 and #{@size}" if i < 0 or i >= @size
|
38
|
+
@array[get_index(i)] &= ~(1 << get_shift(i))
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
# Determines the destination Fixnum who holds this bit.
|
43
|
+
def get_index(i)
|
44
|
+
i/BITS_PER_ITEM
|
45
|
+
end
|
46
|
+
# Returns the <i> offset </i> of the given bit inside a Fixnum
|
47
|
+
def get_shift(i)
|
48
|
+
i%BITS_PER_ITEM
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/lilutils.rb
CHANGED
data/lilutils.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{lilutils}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kedar Mhaswade"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-05-23}
|
13
13
|
s.default_executable = %q{cli-demo}
|
14
14
|
s.description = %q{Provides little utilties. It's a gem by a newbie, but I think it is quite useful. As of now, it provides a nicely abstracted out yes/no/cancel dialog box on a console.}
|
15
15
|
s.email = %q{kedar.mhaswade@gmail.com}
|
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
"lib/lilutils/cli/cli.rb",
|
34
34
|
"lib/lilutils/cli_entry.rb",
|
35
35
|
"lib/lilutils/misc/binary_search.rb",
|
36
|
+
"lib/lilutils/misc/bit_vector.rb",
|
36
37
|
"lib/lilutils/misc/misc.rb",
|
37
38
|
"lib/lilutils/misc/pascal.rb",
|
38
39
|
"lib/lilutils/misc_entry.rb",
|
@@ -43,6 +44,7 @@ Gem::Specification.new do |s|
|
|
43
44
|
"test/algo_test_utils/data_sets_test.rb",
|
44
45
|
"test/cli/cli_basic_test.rb",
|
45
46
|
"test/misc/binary_search_test.rb",
|
47
|
+
"test/misc/bit_vector_test.rb",
|
46
48
|
"test/misc/misc_pascal_test.rb",
|
47
49
|
"test/test_helper.rb",
|
48
50
|
"test/test_lilutils.rb"
|
@@ -56,6 +58,7 @@ Gem::Specification.new do |s|
|
|
56
58
|
"test/algo_test_utils/data_sets_test.rb",
|
57
59
|
"test/cli/cli_basic_test.rb",
|
58
60
|
"test/misc/binary_search_test.rb",
|
61
|
+
"test/misc/bit_vector_test.rb",
|
59
62
|
"test/misc/misc_pascal_test.rb",
|
60
63
|
"test/test_helper.rb",
|
61
64
|
"test/test_lilutils.rb"
|
@@ -65,20 +68,17 @@ Gem::Specification.new do |s|
|
|
65
68
|
s.specification_version = 3
|
66
69
|
|
67
70
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
68
|
-
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
69
71
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
70
72
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
71
73
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
72
74
|
s.add_development_dependency(%q<test-unit>, [">= 0"])
|
73
75
|
else
|
74
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
75
76
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
76
77
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
77
78
|
s.add_dependency(%q<rcov>, [">= 0"])
|
78
79
|
s.add_dependency(%q<test-unit>, [">= 0"])
|
79
80
|
end
|
80
81
|
else
|
81
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
82
82
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
83
83
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
84
84
|
s.add_dependency(%q<rcov>, [">= 0"])
|
@@ -29,4 +29,11 @@ class DataSetsTest < Test::Unit::TestCase
|
|
29
29
|
# DS.select_random_array_to_file(1_000_000, 10_000_000, fn)
|
30
30
|
File.delete(fn)
|
31
31
|
end
|
32
|
+
|
33
|
+
def test_random_strings_successive
|
34
|
+
# two successive invocations of ascii_strings should return unique strings, as far as possible
|
35
|
+
f = DS.ascii_strings(1, 30)
|
36
|
+
s = DS.ascii_strings(1, 30)
|
37
|
+
assert_not_equal(f, s)
|
38
|
+
end
|
32
39
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require_relative "../../lib/lilutils/misc/bit_vector"
|
3
|
+
|
4
|
+
class BitVectorTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
# Called before every test method runs. Can be used
|
7
|
+
# to set up fixture information.
|
8
|
+
def setup
|
9
|
+
# Do nothing
|
10
|
+
end
|
11
|
+
|
12
|
+
# Called after every test method runs. Can be used to tear
|
13
|
+
# down fixture information.
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
# Do nothing
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_set_test_one
|
20
|
+
bv = LilUtils::Misc::BitVector.new(100)
|
21
|
+
bv.set(4)
|
22
|
+
assert_equal(1, bv.test(4))
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_set_clear_one
|
26
|
+
bv = LilUtils::Misc::BitVector.new(1<<20) # 1 Mega-bits = 2**20 bits
|
27
|
+
bv.set(512)
|
28
|
+
bv.clear(512)
|
29
|
+
assert_equal(0, bv.test(512))
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_set_all
|
33
|
+
n = 1_000
|
34
|
+
bv = LilUtils::Misc::BitVector.new(n)
|
35
|
+
0.upto(n-1) {|i| bv.set(i)}
|
36
|
+
0.upto(n-1) {|i| assert_equal(1, bv.test(i))}
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_edge_cases
|
40
|
+
n = 1<<16 #=> 65,536 bits
|
41
|
+
bv = LilUtils::Misc::BitVector.new(n)
|
42
|
+
bv.set(0)
|
43
|
+
assert_equal(1, bv.test(0))
|
44
|
+
bv.set(1<<16-1)
|
45
|
+
assert_equal(1, bv.test(1<<16-1))
|
46
|
+
bv.clear(0)
|
47
|
+
assert_equal(0, bv.test(0))
|
48
|
+
bv.clear(1<<16-1)
|
49
|
+
assert_equal(0, bv.test(1<<16-1))
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/test/test_lilutils.rb
CHANGED
metadata
CHANGED
@@ -1,82 +1,71 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: lilutils
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.2
|
3
|
+
version: !ruby/object:Gem::Version
|
5
4
|
prerelease:
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Kedar Mhaswade
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
12
|
+
|
13
|
+
date: 2011-05-23 00:00:00 -07:00
|
13
14
|
default_executable: cli-demo
|
14
|
-
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: shoulda
|
17
|
-
requirement: &15751660 !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
|
-
requirements:
|
20
|
-
- - ! '>='
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '0'
|
23
|
-
type: :development
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: *15751660
|
26
|
-
- !ruby/object:Gem::Dependency
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
27
17
|
name: bundler
|
28
|
-
requirement: &
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
29
19
|
none: false
|
30
|
-
requirements:
|
20
|
+
requirements:
|
31
21
|
- - ~>
|
32
|
-
- !ruby/object:Gem::Version
|
22
|
+
- !ruby/object:Gem::Version
|
33
23
|
version: 1.0.0
|
34
24
|
type: :development
|
35
25
|
prerelease: false
|
36
|
-
version_requirements: *
|
37
|
-
- !ruby/object:Gem::Dependency
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
38
28
|
name: jeweler
|
39
|
-
requirement: &
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
30
|
none: false
|
41
|
-
requirements:
|
31
|
+
requirements:
|
42
32
|
- - ~>
|
43
|
-
- !ruby/object:Gem::Version
|
33
|
+
- !ruby/object:Gem::Version
|
44
34
|
version: 1.5.2
|
45
35
|
type: :development
|
46
36
|
prerelease: false
|
47
|
-
version_requirements: *
|
48
|
-
- !ruby/object:Gem::Dependency
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
49
39
|
name: rcov
|
50
|
-
requirement: &
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
51
41
|
none: false
|
52
|
-
requirements:
|
53
|
-
- -
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version:
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
56
46
|
type: :development
|
57
47
|
prerelease: false
|
58
|
-
version_requirements: *
|
59
|
-
- !ruby/object:Gem::Dependency
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
60
50
|
name: test-unit
|
61
|
-
requirement: &
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
62
52
|
none: false
|
63
|
-
requirements:
|
64
|
-
- -
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version:
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
67
57
|
type: :development
|
68
58
|
prerelease: false
|
69
|
-
version_requirements: *
|
70
|
-
description: Provides little utilties. It's a gem by a newbie, but I think it is quite
|
71
|
-
useful. As of now, it provides a nicely abstracted out yes/no/cancel dialog box
|
72
|
-
on a console.
|
59
|
+
version_requirements: *id004
|
60
|
+
description: Provides little utilties. It's a gem by a newbie, but I think it is quite useful. As of now, it provides a nicely abstracted out yes/no/cancel dialog box on a console.
|
73
61
|
email: kedar.mhaswade@gmail.com
|
74
|
-
executables:
|
62
|
+
executables:
|
75
63
|
- cli-demo
|
76
64
|
extensions: []
|
77
|
-
|
65
|
+
|
66
|
+
extra_rdoc_files:
|
78
67
|
- README.rdoc
|
79
|
-
files:
|
68
|
+
files:
|
80
69
|
- Gemfile
|
81
70
|
- Gemfile.lock
|
82
71
|
- History.txt
|
@@ -92,6 +81,7 @@ files:
|
|
92
81
|
- lib/lilutils/cli/cli.rb
|
93
82
|
- lib/lilutils/cli_entry.rb
|
94
83
|
- lib/lilutils/misc/binary_search.rb
|
84
|
+
- lib/lilutils/misc/bit_vector.rb
|
95
85
|
- lib/lilutils/misc/misc.rb
|
96
86
|
- lib/lilutils/misc/pascal.rb
|
97
87
|
- lib/lilutils/misc_entry.rb
|
@@ -102,42 +92,46 @@ files:
|
|
102
92
|
- test/algo_test_utils/data_sets_test.rb
|
103
93
|
- test/cli/cli_basic_test.rb
|
104
94
|
- test/misc/binary_search_test.rb
|
95
|
+
- test/misc/bit_vector_test.rb
|
105
96
|
- test/misc/misc_pascal_test.rb
|
106
97
|
- test/test_helper.rb
|
107
98
|
- test/test_lilutils.rb
|
108
99
|
has_rdoc: true
|
109
100
|
homepage: http://github.com/kedarmhaswade/lilutils
|
110
|
-
licenses:
|
101
|
+
licenses:
|
111
102
|
- MIT
|
112
103
|
post_install_message:
|
113
104
|
rdoc_options: []
|
114
|
-
|
105
|
+
|
106
|
+
require_paths:
|
115
107
|
- lib
|
116
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
109
|
none: false
|
118
|
-
requirements:
|
119
|
-
- -
|
120
|
-
- !ruby/object:Gem::Version
|
121
|
-
|
122
|
-
segments:
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: 2948204278225597080
|
114
|
+
segments:
|
123
115
|
- 0
|
124
|
-
|
125
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
version: "0"
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
118
|
none: false
|
127
|
-
requirements:
|
128
|
-
- -
|
129
|
-
- !ruby/object:Gem::Version
|
130
|
-
version:
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: "0"
|
131
123
|
requirements: []
|
124
|
+
|
132
125
|
rubyforge_project:
|
133
126
|
rubygems_version: 1.6.2
|
134
127
|
signing_key:
|
135
128
|
specification_version: 3
|
136
129
|
summary: Little utilities for everyone
|
137
|
-
test_files:
|
130
|
+
test_files:
|
138
131
|
- test/algo_test_utils/data_sets_test.rb
|
139
132
|
- test/cli/cli_basic_test.rb
|
140
133
|
- test/misc/binary_search_test.rb
|
134
|
+
- test/misc/bit_vector_test.rb
|
141
135
|
- test/misc/misc_pascal_test.rb
|
142
136
|
- test/test_helper.rb
|
143
137
|
- test/test_lilutils.rb
|