bitmap 0.0.3.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bitmap.rb +64 -62
- metadata +20 -28
data/lib/bitmap.rb
CHANGED
@@ -2,84 +2,86 @@
|
|
2
2
|
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
3
|
# Version 2, December 2004
|
4
4
|
#
|
5
|
-
# Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
|
6
|
-
#
|
7
5
|
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
8
6
|
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
9
7
|
#
|
10
8
|
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
11
9
|
#++
|
12
10
|
|
13
|
-
class Bitmap
|
14
|
-
|
15
|
-
|
11
|
+
class Bitmap
|
12
|
+
class Value
|
13
|
+
attr_reader :bitmap
|
14
|
+
|
15
|
+
def initialize (bitmap, value, names)
|
16
|
+
@bitmap = bitmap
|
17
|
+
@value = value.to_i
|
18
|
+
@names = names
|
19
|
+
end
|
16
20
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
def has? (mask)
|
22
|
+
if mask.is_a?(Value)
|
23
|
+
(@names.to_a & mask.to_a) == mask.to_a
|
24
|
+
else
|
25
|
+
@names.member?(mask.to_s.to_sym)
|
26
|
+
end
|
27
|
+
end
|
22
28
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
else
|
27
|
-
@names.member?(mask.to_s.to_sym)
|
28
|
-
end
|
29
|
-
end
|
29
|
+
def to_a
|
30
|
+
@names
|
31
|
+
end
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
def + (*what)
|
34
|
+
bitmap[*(@names + what.flatten.map {|piece|
|
35
|
+
piece.to_a rescue piece
|
36
|
+
}).flatten.compact]
|
37
|
+
end
|
34
38
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
def - (*what)
|
40
|
+
bitmap[*(@names - what.flatten.map {|piece|
|
41
|
+
piece.to_a rescue piece
|
42
|
+
}).flatten.compact]
|
43
|
+
end
|
40
44
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
}).flatten.compact]
|
45
|
-
end
|
45
|
+
def to_i
|
46
|
+
@value
|
47
|
+
end
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
-
|
49
|
+
def to_s
|
50
|
+
to_a.join '|'
|
51
|
+
end
|
52
|
+
end
|
50
53
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
54
|
+
def initialize (data)
|
55
|
+
@bits = data
|
56
|
+
@bits.freeze
|
57
|
+
end
|
55
58
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
59
|
+
def [] (*args)
|
60
|
+
args.flatten!
|
61
|
+
args.compact!
|
60
62
|
|
61
|
-
|
62
|
-
|
63
|
-
|
63
|
+
if args.length == 1 && args.first.is_a?(Integer)
|
64
|
+
Value.new(self, args.first, args.first.to_s(2).reverse.chars.each_with_index.map {|bit, index|
|
65
|
+
next if bit.to_i.zero?
|
64
66
|
|
65
|
-
|
66
|
-
|
67
|
-
|
67
|
+
@bits.key("#{bit}#{'0' * index}".to_i(2)) or raise ArgumentError, "unknown bit at #{index}"
|
68
|
+
}.compact)
|
69
|
+
else
|
70
|
+
Value.new(self, args.map {|arg|
|
71
|
+
@bits[arg] or @bits[arg.to_s.to_sym] or raise ArgumentError, "unknown symbol #{arg}"
|
72
|
+
}.inject {|a, b|
|
73
|
+
a | b
|
74
|
+
}, args)
|
75
|
+
end
|
76
|
+
end
|
68
77
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
}.inject {|a, b|
|
75
|
-
a | b
|
76
|
-
}, args)
|
77
|
-
end
|
78
|
-
end
|
78
|
+
def all
|
79
|
+
Value.new(self, @bits.values.inject {|a, b|
|
80
|
+
a | b
|
81
|
+
}, @bits.keys)
|
82
|
+
end
|
79
83
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
}, keys)
|
84
|
-
end
|
84
|
+
def inspect
|
85
|
+
"#<#{self.class.name}: #{@bits.map { |name, bit| "#{bit.to_s(16)}=#{name}" }.join ' '}>"
|
86
|
+
end
|
85
87
|
end
|
metadata
CHANGED
@@ -1,54 +1,46 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitmap
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.3.2
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- meh.
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
date: 2011-08-21 00:00:00 Z
|
12
|
+
date: 2012-07-17 00:00:00.000000000 Z
|
14
13
|
dependencies: []
|
15
|
-
|
16
14
|
description:
|
17
15
|
email: meh@paranoici.org
|
18
16
|
executables: []
|
19
|
-
|
20
17
|
extensions: []
|
21
|
-
|
22
18
|
extra_rdoc_files: []
|
23
|
-
|
24
|
-
files:
|
19
|
+
files:
|
25
20
|
- lib/bitmap.rb
|
26
21
|
homepage: http://github.com/meh/ruby-bitmap
|
27
22
|
licenses: []
|
28
|
-
|
29
23
|
post_install_message:
|
30
24
|
rdoc_options: []
|
31
|
-
|
32
|
-
require_paths:
|
25
|
+
require_paths:
|
33
26
|
- lib
|
34
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
28
|
none: false
|
36
|
-
requirements:
|
37
|
-
- -
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version:
|
40
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
34
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version:
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
46
39
|
requirements: []
|
47
|
-
|
48
40
|
rubyforge_project:
|
49
|
-
rubygems_version: 1.8.
|
41
|
+
rubygems_version: 1.8.24
|
50
42
|
signing_key:
|
51
43
|
specification_version: 3
|
52
|
-
summary: Simple and stupid bitmap implementation (bitmap as in bitset, not bitmap
|
44
|
+
summary: Simple and stupid bitmap implementation (bitmap as in bitset, not bitmap
|
45
|
+
image)
|
53
46
|
test_files: []
|
54
|
-
|