You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21-10Lines changed: 21 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,21 +2,32 @@
2
2
3
3
Basic, pure Ruby bit field. Pretty fast (for what it is) and memory efficient. Works well for Bloom filters (the reason I wrote it).
4
4
5
-
Written in 2007 and not updated since then, just bringing it on to GitHub by user request. It used to be called Bitfield and was hosted at http://snippets.dzone.com/posts/show/4234
5
+
Written in 2007 and not updated since then, just bringing it on to GitHub by user request. It used to be called Bitfield and was hosted at http://snippets.dzone.com/posts/show/4234 .. I will review the code and bring the docs up to date in due course.
6
+
7
+
## Installation
8
+
9
+
gem install bitarray
6
10
7
11
## Examples
8
12
9
-
Create a bit field 1000 bits wide
10
-
bf = BitField.new(1000)
13
+
To use:
14
+
15
+
require 'bitarray'
16
+
17
+
Create a bit field 1000 bits wide:
18
+
19
+
ba = BitArray.new(1000)
20
+
21
+
Setting and reading bits:
22
+
23
+
ba[100] = 1
24
+
ba[100] .. => 1
25
+
ba[100] = 0
11
26
12
-
Setting and reading bits
13
-
bf[100] = 1
14
-
bf[100] .. => 1
15
-
bf[100] = 0
27
+
More:
16
28
17
-
More
18
-
bf.to_s = "10101000101010101" (example)
19
-
bf.total_set .. => 10 (example - 10 bits are set to "1")
29
+
ba.to_s = "10101000101010101" (example)
30
+
ba.total_set .. => 10 (example - 10 bits are set to "1")
0 commit comments