ewah-bitset 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 +3 -1
- data/README.md +6 -0
- data/ewah-bitset.gemspec +2 -2
- data/ext/ewah-bitset.cpp +60 -2
- data/spec/ewah_bitset_spec.rb +32 -0
- metadata +4 -4
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -6,6 +6,12 @@ This library wraps the original C++ implementation written by one of the origina
|
|
6
6
|
|
7
7
|
https://github.com/lemire/EWAHBoolArray
|
8
8
|
|
9
|
+
The gem is built and tested against ruby 1.8.7. If anyone wants to modify it to also run in ruby 1.9.x I'd gladly accept the pull requests.
|
10
|
+
|
11
|
+
To install simply run
|
12
|
+
|
13
|
+
gem install ewah-bitset
|
14
|
+
|
9
15
|
Examples are in the spec but the general idea goes something like this:
|
10
16
|
|
11
17
|
require 'ewahbitset'
|
data/ewah-bitset.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "ewah-bitset"
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Josh Ferguson"]
|
9
|
-
s.date = "2012-04-
|
9
|
+
s.date = "2012-04-23"
|
10
10
|
s.description = "A wrapper around Lemire's EWAHBoolArray from https://github.com/lemire/EWAHBoolArray"
|
11
11
|
s.email = "josh@besquared.net"
|
12
12
|
s.extensions = ["ext/extconf.rb"]
|
data/ext/ewah-bitset.cpp
CHANGED
@@ -47,6 +47,32 @@ extern "C" VALUE ewah_each(VALUE self) {
|
|
47
47
|
return Qnil;
|
48
48
|
}
|
49
49
|
|
50
|
+
extern "C" VALUE ewah_each_word(VALUE self) {
|
51
|
+
EWAH *bitset;
|
52
|
+
Data_Get_Struct(self, EWAH, bitset);
|
53
|
+
|
54
|
+
EWAHBoolArrayIterator<uword64> i = bitset->bits->uncompress();
|
55
|
+
|
56
|
+
while(i.hasNext()) {
|
57
|
+
rb_yield(INT2FIX(i.next()));
|
58
|
+
}
|
59
|
+
|
60
|
+
return Qnil;
|
61
|
+
}
|
62
|
+
|
63
|
+
extern "C" VALUE ewah_each_word_sparse(VALUE self) {
|
64
|
+
EWAH *bitset;
|
65
|
+
Data_Get_Struct(self, EWAH, bitset);
|
66
|
+
|
67
|
+
EWAHBoolArraySparseIterator<uword64> i = bitset->bits->sparse_uncompress();
|
68
|
+
|
69
|
+
while(i.hasNext()) {
|
70
|
+
rb_yield(INT2FIX(i.next()));
|
71
|
+
}
|
72
|
+
|
73
|
+
return Qnil;
|
74
|
+
}
|
75
|
+
|
50
76
|
extern "C" VALUE ewah_swap(VALUE self, VALUE other) {
|
51
77
|
EWAH *bitset;
|
52
78
|
EWAH *obitset;
|
@@ -96,7 +122,20 @@ extern "C" VALUE ewah_logical_and(VALUE self, VALUE other) {
|
|
96
122
|
return newBitset;
|
97
123
|
}
|
98
124
|
|
99
|
-
extern "C" VALUE
|
125
|
+
extern "C" VALUE ewah_logical_not(VALUE self) {
|
126
|
+
EWAH *bitset;
|
127
|
+
Data_Get_Struct(self, EWAH, bitset);
|
128
|
+
|
129
|
+
VALUE newBitset = ewah_new(rb_path2class("EwahBitset"));
|
130
|
+
|
131
|
+
EWAH *newBits;
|
132
|
+
Data_Get_Struct(newBitset, EWAH, newBits);
|
133
|
+
bitset->bits->logicalnot(*(newBits->bits));
|
134
|
+
|
135
|
+
return newBitset;
|
136
|
+
}
|
137
|
+
|
138
|
+
extern "C" VALUE ewah_eq(VALUE self, VALUE other) {
|
100
139
|
EWAH *bitset;
|
101
140
|
EWAH *obitset;
|
102
141
|
Data_Get_Struct(self, EWAH, bitset);
|
@@ -109,6 +148,19 @@ extern "C" VALUE ewah_equals(VALUE self, VALUE other) {
|
|
109
148
|
}
|
110
149
|
}
|
111
150
|
|
151
|
+
extern "C" VALUE ewah_neq(VALUE self, VALUE other) {
|
152
|
+
EWAH *bitset;
|
153
|
+
EWAH *obitset;
|
154
|
+
Data_Get_Struct(self, EWAH, bitset);
|
155
|
+
Data_Get_Struct(other, EWAH, obitset);
|
156
|
+
|
157
|
+
if(*(bitset->bits) != *(obitset->bits)) {
|
158
|
+
return Qtrue;
|
159
|
+
} else {
|
160
|
+
return Qfalse;
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
112
164
|
/* Information & Serialization */
|
113
165
|
extern "C" VALUE ewah_size_in_bits(VALUE self) {
|
114
166
|
EWAH *bitset;
|
@@ -164,9 +216,15 @@ extern "C" void Init_ewahbitset() {
|
|
164
216
|
rb_define_method(rb_cC, "swap", (ruby_method*) &ewah_swap, 1);
|
165
217
|
rb_define_method(rb_cC, "reset", (ruby_method*) &ewah_reset, 0);
|
166
218
|
|
167
|
-
rb_define_method(rb_cC, "
|
219
|
+
rb_define_method(rb_cC, "each_word64", (ruby_method*) &ewah_each_word, 0);
|
220
|
+
rb_define_method(rb_cC, "each_word64_sparse", (ruby_method*) &ewah_each_word_sparse, 0);
|
221
|
+
|
222
|
+
rb_define_method(rb_cC, "==", (ruby_method*) &ewah_eq, 1);
|
223
|
+
rb_define_method(rb_cC, "!=", (ruby_method*) &ewah_neq, 1);
|
224
|
+
|
168
225
|
rb_define_method(rb_cC, "logical_or", (ruby_method*) &ewah_logical_or, 1);
|
169
226
|
rb_define_method(rb_cC, "logical_and", (ruby_method*) &ewah_logical_and, 1);
|
227
|
+
rb_define_method(rb_cC, "logical_not", (ruby_method*) &ewah_logical_not, 1);
|
170
228
|
|
171
229
|
rb_define_method(rb_cC, "to_binary_s", (ruby_method*) &ewah_to_binary_s, 0);
|
172
230
|
rb_define_method(rb_cC, "serialize", (ruby_method*) &ewah_serialize, 0);
|
data/spec/ewah_bitset_spec.rb
CHANGED
@@ -99,4 +99,36 @@ describe "An EwahBitset" do
|
|
99
99
|
|
100
100
|
@bitset.should == newbits
|
101
101
|
end
|
102
|
+
|
103
|
+
it "should iterate over each 64 bit word" do
|
104
|
+
0.upto(10) do |i|
|
105
|
+
@bitset.set(i)
|
106
|
+
end
|
107
|
+
|
108
|
+
output = []
|
109
|
+
@bitset.each_word64 do |word|
|
110
|
+
0.upto(64) do |i|
|
111
|
+
output << ((word >> i) & 0x01)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
output[0,11].uniq.should == [1]
|
116
|
+
output[11,53].uniq.should == [0]
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should iterate over each 64 bit word sparsely" do
|
120
|
+
0.upto(10) do |i|
|
121
|
+
@bitset.set(i)
|
122
|
+
end
|
123
|
+
|
124
|
+
output = []
|
125
|
+
@bitset.each_word64_sparse do |word|
|
126
|
+
0.upto(64) do |i|
|
127
|
+
output << ((word >> i) & 0x01)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
output[0,11].uniq.should == [1]
|
132
|
+
output[11,53].uniq.should == [0]
|
133
|
+
end
|
102
134
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ewah-bitset
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Josh Ferguson
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-04-
|
18
|
+
date: 2012-04-23 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: A wrapper around Lemire's EWAHBoolArray from https://github.com/lemire/EWAHBoolArray
|