bitstring 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/CONTRIBUTORS.txt +5 -0
  2. data/Changelog.txt +20 -0
  3. data/LICENCE.txt +202 -0
  4. data/NOTICE.txt +5 -0
  5. data/README.txt +63 -0
  6. data/doc/classes/BitString.html +2479 -0
  7. data/doc/classes/BitString.src/M000001.html +99 -0
  8. data/doc/classes/BitString.src/M000002.html +18 -0
  9. data/doc/classes/BitString.src/M000003.html +20 -0
  10. data/doc/classes/BitString.src/M000004.html +19 -0
  11. data/doc/classes/BitString.src/M000005.html +24 -0
  12. data/doc/classes/BitString.src/M000006.html +44 -0
  13. data/doc/classes/BitString.src/M000007.html +21 -0
  14. data/doc/classes/BitString.src/M000008.html +18 -0
  15. data/doc/classes/BitString.src/M000009.html +18 -0
  16. data/doc/classes/BitString.src/M000010.html +22 -0
  17. data/doc/classes/BitString.src/M000011.html +29 -0
  18. data/doc/classes/BitString.src/M000012.html +22 -0
  19. data/doc/classes/BitString.src/M000013.html +43 -0
  20. data/doc/classes/BitString.src/M000014.html +19 -0
  21. data/doc/classes/BitString.src/M000015.html +40 -0
  22. data/doc/classes/BitString.src/M000016.html +21 -0
  23. data/doc/classes/BitString.src/M000017.html +18 -0
  24. data/doc/classes/BitString.src/M000018.html +18 -0
  25. data/doc/classes/BitString.src/M000019.html +18 -0
  26. data/doc/classes/BitString.src/M000020.html +20 -0
  27. data/doc/classes/BitString.src/M000021.html +24 -0
  28. data/doc/classes/BitString.src/M000022.html +23 -0
  29. data/doc/classes/BitString.src/M000023.html +42 -0
  30. data/doc/classes/BitString.src/M000024.html +61 -0
  31. data/doc/classes/BitString.src/M000025.html +18 -0
  32. data/doc/classes/BitString.src/M000026.html +18 -0
  33. data/doc/classes/BitString.src/M000027.html +20 -0
  34. data/doc/classes/BitString.src/M000028.html +18 -0
  35. data/doc/classes/BitString.src/M000029.html +18 -0
  36. data/doc/classes/BitString.src/M000030.html +18 -0
  37. data/doc/classes/BitString.src/M000031.html +18 -0
  38. data/doc/classes/BitString.src/M000032.html +18 -0
  39. data/doc/created.rid +1 -0
  40. data/doc/files/lib/bitstring/operators_rb.html +122 -0
  41. data/doc/files/lib/bitstring_rb.html +153 -0
  42. data/doc/fr_class_index.html +27 -0
  43. data/doc/fr_file_index.html +28 -0
  44. data/doc/fr_method_index.html +60 -0
  45. data/doc/index.html +24 -0
  46. data/doc/rdoc-style.css +208 -0
  47. data/lib/bitstring.rb +1318 -0
  48. data/lib/bitstring/operators.rb +481 -0
  49. data/test/Rakefile +21 -0
  50. data/test/test_basic.rb +848 -0
  51. data/test/test_data.rb +24 -0
  52. data/test/test_enum.rb +671 -0
  53. data/test/test_helper.rb +3 -0
  54. data/test/test_operators.rb +454 -0
  55. metadata +121 -0
@@ -0,0 +1,99 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>new (BitString)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/bitstring.rb, line 249</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args_p</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
15
+ <span class="ruby-comment cmt">#</span>
16
+ <span class="ruby-comment cmt"># Two constructor scenarios:</span>
17
+ <span class="ruby-comment cmt">#</span>
18
+ <span class="ruby-comment cmt"># 1. With a block and an optional length (defaults to 1)</span>
19
+ <span class="ruby-comment cmt"># 2. No block, and with value and length both optional.</span>
20
+ <span class="ruby-comment cmt">#</span>
21
+ <span class="ruby-comment cmt"># We don't do any type-checking on the arguments until later.</span>
22
+ <span class="ruby-comment cmt">#</span>
23
+ <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">block</span>.<span class="ruby-identifier">nil?</span>)
24
+ <span class="ruby-comment cmt">#</span>
25
+ <span class="ruby-comment cmt"># We got a block; set up the constraints. Bitstrings constructed</span>
26
+ <span class="ruby-comment cmt"># this way are bounded.</span>
27
+ <span class="ruby-comment cmt">#</span>
28
+ <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">args_p</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">2</span>)
29
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">'only bitstring length '</span> <span class="ruby-operator">+</span>
30
+ <span class="ruby-value str">'may be specified with a block'</span>)
31
+ <span class="ruby-keyword kw">end</span>
32
+ <span class="ruby-ivar">@bounded</span> = <span class="ruby-keyword kw">true</span>
33
+ <span class="ruby-ivar">@length</span> = <span class="ruby-identifier">args_p</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">args_p</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">:</span> <span class="ruby-value">1</span>
34
+ <span class="ruby-keyword kw">else</span>
35
+ <span class="ruby-comment cmt">#</span>
36
+ <span class="ruby-comment cmt"># Get value and possibly length from the argument list.</span>
37
+ <span class="ruby-comment cmt">#</span>
38
+ <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">args_p</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">3</span>)
39
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">'wrong number of arguments '</span> <span class="ruby-operator">+</span>
40
+ <span class="ruby-value str">'(must be 2 or fewer)'</span>)
41
+ <span class="ruby-keyword kw">end</span>
42
+ <span class="ruby-identifier">val</span> = <span class="ruby-identifier">args_p</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">||</span> <span class="ruby-value">0</span>
43
+ <span class="ruby-ivar">@length</span> = <span class="ruby-identifier">args_p</span>[<span class="ruby-value">1</span>] <span class="ruby-keyword kw">if</span> (<span class="ruby-ivar">@bounded</span> = <span class="ruby-operator">!</span> <span class="ruby-identifier">args_p</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">nil?</span>)
44
+ <span class="ruby-keyword kw">end</span>
45
+ <span class="ruby-comment cmt">#</span>
46
+ <span class="ruby-comment cmt"># Now do some validation on the arguments.</span>
47
+ <span class="ruby-comment cmt">#</span>
48
+ <span class="ruby-keyword kw">if</span> (<span class="ruby-ivar">@bounded</span>)
49
+ <span class="ruby-keyword kw">unless</span> ((<span class="ruby-ivar">@length</span> = <span class="ruby-ivar">@length</span>.<span class="ruby-identifier">to_i</span>) <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>)
50
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">'bitstring length must be greater than 0'</span>)
51
+ <span class="ruby-keyword kw">end</span>
52
+ <span class="ruby-keyword kw">end</span>
53
+ <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">block</span>.<span class="ruby-identifier">nil?</span>)
54
+ <span class="ruby-comment cmt">#</span>
55
+ <span class="ruby-comment cmt"># We weren't passed a block, so get the info directly from the argument</span>
56
+ <span class="ruby-comment cmt"># list.</span>
57
+ <span class="ruby-comment cmt">#</span>
58
+ <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">val</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">BitString</span>))
59
+ <span class="ruby-comment cmt">#</span>
60
+ <span class="ruby-comment cmt"># If we were passed a bitstring, convert it.</span>
61
+ <span class="ruby-comment cmt">#</span>
62
+ <span class="ruby-ivar">@value</span> = <span class="ruby-identifier">val</span>.<span class="ruby-identifier">to_i</span>
63
+ <span class="ruby-keyword kw">elsif</span> (<span class="ruby-identifier">val</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">String</span>))
64
+ <span class="ruby-comment cmt">#</span>
65
+ <span class="ruby-comment cmt"># If we were given a String for the value, it must consist of valid</span>
66
+ <span class="ruby-comment cmt"># binary digits.</span>
67
+ <span class="ruby-comment cmt">#</span>
68
+ <span class="ruby-identifier">_raise</span>(<span class="ruby-constant">BadDigit</span>, <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">val</span>) <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">val</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/[01]/</span>, <span class="ruby-value str">''</span>).<span class="ruby-identifier">empty?</span>)
69
+ <span class="ruby-ivar">@value</span> = <span class="ruby-identifier">val</span>.<span class="ruby-identifier">to_i</span>(<span class="ruby-value">2</span>)
70
+ <span class="ruby-keyword kw">elsif</span> (<span class="ruby-identifier">val</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Array</span>))
71
+ <span class="ruby-comment cmt">#</span>
72
+ <span class="ruby-comment cmt"># If we were given an array, make sure that all the values are</span>
73
+ <span class="ruby-comment cmt"># integers and either 1 or 0.</span>
74
+ <span class="ruby-comment cmt">#</span>
75
+ <span class="ruby-identifier">_raise</span>(<span class="ruby-constant">BadDigit</span>, <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">val</span>) <span class="ruby-keyword kw">unless</span> ((<span class="ruby-identifier">val</span> <span class="ruby-operator">-</span> [<span class="ruby-value">0</span>, <span class="ruby-value">1</span>]).<span class="ruby-identifier">empty?</span>)
76
+ <span class="ruby-ivar">@value</span> = <span class="ruby-identifier">val</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">''</span>).<span class="ruby-identifier">to_i</span>(<span class="ruby-value">2</span>)
77
+ <span class="ruby-keyword kw">else</span>
78
+ <span class="ruby-comment cmt">#</span>
79
+ <span class="ruby-comment cmt"># Let's try to convert it to an integer from whatever class we</span>
80
+ <span class="ruby-comment cmt"># were passed.</span>
81
+ <span class="ruby-comment cmt">#</span>
82
+ <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">val</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:to_i</span>))
83
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">'unable to determine bitstring '</span> <span class="ruby-operator">+</span>
84
+ <span class="ruby-value str">'value from '</span> <span class="ruby-operator">+</span>
85
+ <span class="ruby-node">&quot;\&quot;#{val.to_s}\&quot;:#{val.class.name}&quot;</span>)
86
+ <span class="ruby-keyword kw">end</span>
87
+ <span class="ruby-ivar">@value</span> = <span class="ruby-identifier">val</span>.<span class="ruby-identifier">to_i</span>
88
+ <span class="ruby-keyword kw">end</span>
89
+ <span class="ruby-keyword kw">else</span>
90
+ <span class="ruby-comment cmt">#</span>
91
+ <span class="ruby-comment cmt"># We were passed a block, so invoke it for each bit position to</span>
92
+ <span class="ruby-comment cmt"># determine that bit's value from the LSB of the result.</span>
93
+ <span class="ruby-comment cmt">#</span>
94
+ <span class="ruby-ivar">@value</span> = <span class="ruby-value">0</span>
95
+ <span class="ruby-ivar">@length</span>.<span class="ruby-identifier">times</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">i</span>] = <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">i</span>).<span class="ruby-identifier">to_i</span> <span class="ruby-operator">&amp;</span> <span class="ruby-value">1</span> }
96
+ <span class="ruby-keyword kw">end</span>
97
+ <span class="ruby-keyword kw">end</span></pre>
98
+ </body>
99
+ </html>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>bounded? (BitString)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/bitstring.rb, line 463</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">bounded?</span>()
15
+ <span class="ruby-ivar">@bounded</span>
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>clear (BitString)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/bitstring.rb, line 481</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear</span>()
15
+ <span class="ruby-identifier">bs</span> = <span class="ruby-identifier">dup</span>
16
+ <span class="ruby-identifier">bs</span>.<span class="ruby-identifier">from_i</span>(<span class="ruby-value">0</span>)
17
+ <span class="ruby-identifier">bs</span>
18
+ <span class="ruby-keyword kw">end</span></pre>
19
+ </body>
20
+ </html>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>clear! (BitString)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/bitstring.rb, line 501</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear!</span>()
15
+ <span class="ruby-ivar">@value</span> = <span class="ruby-value">0</span>
16
+ <span class="ruby-keyword kw">self</span>
17
+ <span class="ruby-keyword kw">end</span></pre>
18
+ </body>
19
+ </html>
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>from_i (BitString)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/bitstring.rb, line 521</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">from_i</span>(<span class="ruby-identifier">newval</span>)
15
+ <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">newval</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:to_i</span>))
16
+ <span class="ruby-identifier">what</span> = <span class="ruby-identifier">newval</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:to_s</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">newval</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">newval</span>.<span class="ruby-identifier">inspect</span>
17
+ <span class="ruby-identifier">_raise</span>(<span class="ruby-constant">UnInterable</span>, <span class="ruby-identifier">newval</span>)
18
+ <span class="ruby-keyword kw">end</span>
19
+ <span class="ruby-identifier">newval</span> = <span class="ruby-identifier">newval</span>.<span class="ruby-identifier">to_i</span>
20
+ <span class="ruby-identifier">newval</span> <span class="ruby-operator">&amp;=</span> <span class="ruby-value">2</span><span class="ruby-operator">**</span><span class="ruby-ivar">@length</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span> <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">bounded?</span>)
21
+ <span class="ruby-ivar">@value</span> = <span class="ruby-identifier">newval</span>
22
+ <span class="ruby-keyword kw">end</span></pre>
23
+ </body>
24
+ </html>
@@ -0,0 +1,44 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>grow (BitString)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/bitstring.rb, line 553</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">grow</span>(<span class="ruby-identifier">bits</span>=<span class="ruby-value">1</span>, <span class="ruby-identifier">defval</span>=<span class="ruby-value">0</span>, <span class="ruby-identifier">direction</span>=<span class="ruby-constant">HIGH_END</span>)
15
+ <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">bits</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Integer</span>))
16
+ <span class="ruby-identifier">_raise</span>(<span class="ruby-constant">BitsRInts</span>)
17
+ <span class="ruby-keyword kw">end</span>
18
+ <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">defval</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:to_i</span>))
19
+ <span class="ruby-identifier">what</span> = <span class="ruby-identifier">defval</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:to_s</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">defval</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">defval</span>.<span class="ruby-identifier">inspect</span>
20
+ <span class="ruby-identifier">_raise</span>(<span class="ruby-constant">UnInterable</span>, <span class="ruby-identifier">defval</span>)
21
+ <span class="ruby-keyword kw">end</span>
22
+ <span class="ruby-keyword kw">unless</span> ([<span class="ruby-constant">HIGH_END</span>, <span class="ruby-constant">LOW_END</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">direction</span>))
23
+ <span class="ruby-identifier">_raise</span>(<span class="ruby-constant">NeedGPS</span>)
24
+ <span class="ruby-keyword kw">end</span>
25
+ <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">bits</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-value">0</span>)
26
+ <span class="ruby-identifier">_raise</span>(<span class="ruby-constant">NoDeficitBits</span>)
27
+ <span class="ruby-keyword kw">end</span>
28
+ <span class="ruby-keyword kw">unless</span> ((<span class="ruby-identifier">direction</span> <span class="ruby-operator">==</span> <span class="ruby-constant">LOW_END</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">bounded?</span>)
29
+ <span class="ruby-identifier">_raise</span>(<span class="ruby-constant">UnboundedNonsense</span>)
30
+ <span class="ruby-keyword kw">end</span>
31
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">dup</span> <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">bits</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>)
32
+
33
+ <span class="ruby-identifier">value</span> = <span class="ruby-ivar">@value</span>
34
+ <span class="ruby-identifier">mask</span> = <span class="ruby-value">2</span><span class="ruby-operator">**</span><span class="ruby-identifier">bits</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
35
+ <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">direction</span> <span class="ruby-operator">==</span> <span class="ruby-constant">HIGH_END</span>)
36
+ <span class="ruby-identifier">mask</span> <span class="ruby-operator">*=</span> <span class="ruby-value">2</span><span class="ruby-operator">**</span><span class="ruby-ivar">@length</span> <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">bounded?</span>)
37
+ <span class="ruby-keyword kw">elsif</span> (<span class="ruby-identifier">direction</span> <span class="ruby-operator">==</span> <span class="ruby-constant">LOW_END</span>)
38
+ <span class="ruby-identifier">value</span> <span class="ruby-operator">*=</span> (<span class="ruby-value">2</span><span class="ruby-operator">**</span><span class="ruby-identifier">bits</span>)
39
+ <span class="ruby-keyword kw">end</span>
40
+ <span class="ruby-identifier">value</span> <span class="ruby-operator">|=</span> <span class="ruby-identifier">mask</span> <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">defval</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>)
41
+ <span class="ruby-identifier">bounded?</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">value</span>, <span class="ruby-ivar">@length</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">bits</span>) <span class="ruby-operator">:</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">value</span>)
42
+ <span class="ruby-keyword kw">end</span></pre>
43
+ </body>
44
+ </html>
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>grow! (BitString)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/bitstring.rb, line 604</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">grow!</span>(<span class="ruby-identifier">bits</span>=<span class="ruby-value">1</span>, <span class="ruby-identifier">defval</span>=<span class="ruby-value">0</span>, <span class="ruby-identifier">direction</span>=<span class="ruby-constant">HIGH_END</span>)
15
+ <span class="ruby-identifier">bs</span> = <span class="ruby-identifier">grow</span>(<span class="ruby-identifier">bits</span>, <span class="ruby-identifier">defval</span>, <span class="ruby-identifier">direction</span>)
16
+ <span class="ruby-ivar">@length</span> = <span class="ruby-identifier">bs</span>.<span class="ruby-identifier">length</span> <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">bs</span>.<span class="ruby-identifier">bounded?</span>)
17
+ <span class="ruby-ivar">@value</span> = <span class="ruby-identifier">bs</span>.<span class="ruby-identifier">to_i</span>
18
+ <span class="ruby-keyword kw">self</span>
19
+ <span class="ruby-keyword kw">end</span></pre>
20
+ </body>
21
+ </html>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>length (BitString)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/bitstring.rb, line 626</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">length</span>()
15
+ <span class="ruby-ivar">@bounded</span> <span class="ruby-operator">?</span> <span class="ruby-ivar">@length</span> <span class="ruby-operator">:</span> <span class="ruby-ivar">@value</span>.<span class="ruby-identifier">to_s</span>(<span class="ruby-value">2</span>).<span class="ruby-identifier">length</span>
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>lsb (BitString)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/bitstring.rb, line 644</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">lsb</span>()
15
+ <span class="ruby-keyword kw">self</span>[<span class="ruby-value">0</span>]
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>msb (BitString)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/bitstring.rb, line 663</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">msb</span>()
15
+ <span class="ruby-keyword kw">unless</span> (<span class="ruby-ivar">@bounded</span>)
16
+ <span class="ruby-identifier">_raise</span>(<span class="ruby-constant">UnboundedNonsense</span>,
17
+ <span class="ruby-value str">'most significant bit only applies to bounded bitstrings'</span>)
18
+ <span class="ruby-keyword kw">end</span>
19
+ <span class="ruby-keyword kw">self</span>[<span class="ruby-ivar">@length</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>]
20
+ <span class="ruby-keyword kw">end</span></pre>
21
+ </body>
22
+ </html>
@@ -0,0 +1,29 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>resize (BitString)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/bitstring.rb, line 688</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">resize</span>(<span class="ruby-identifier">bits</span>)
15
+ <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">bits</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Integer</span>))
16
+ <span class="ruby-identifier">_raise</span>(<span class="ruby-constant">BitsRInts</span>)
17
+ <span class="ruby-keyword kw">end</span>
18
+ <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">bits</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>)
19
+ <span class="ruby-identifier">_raise</span>(<span class="ruby-constant">NoDeficitBits</span>)
20
+ <span class="ruby-keyword kw">end</span>
21
+
22
+ <span class="ruby-identifier">value</span> = <span class="ruby-ivar">@value</span>
23
+ <span class="ruby-identifier">length</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">length</span>
24
+ <span class="ruby-identifier">bs</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">value</span>, <span class="ruby-identifier">length</span>)
25
+ <span class="ruby-identifier">diffbits</span> = <span class="ruby-identifier">bits</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">length</span>
26
+ <span class="ruby-identifier">diffbits</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">bs</span>.<span class="ruby-identifier">shrink!</span>(<span class="ruby-operator">-</span><span class="ruby-identifier">diffbits</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">bs</span>.<span class="ruby-identifier">grow!</span>(<span class="ruby-identifier">diffbits</span>)
27
+ <span class="ruby-keyword kw">end</span></pre>
28
+ </body>
29
+ </html>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>resize! (BitString)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/bitstring.rb, line 717</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">resize!</span>(<span class="ruby-identifier">bits</span>)
15
+ <span class="ruby-identifier">bs</span> = <span class="ruby-identifier">resize</span>(<span class="ruby-identifier">bits</span>)
16
+ <span class="ruby-ivar">@bounded</span> = <span class="ruby-keyword kw">true</span>
17
+ <span class="ruby-ivar">@length</span> = <span class="ruby-identifier">bs</span>.<span class="ruby-identifier">length</span>
18
+ <span class="ruby-ivar">@value</span> = <span class="ruby-identifier">bs</span>.<span class="ruby-identifier">to_i</span>
19
+ <span class="ruby-keyword kw">self</span>
20
+ <span class="ruby-keyword kw">end</span></pre>
21
+ </body>
22
+ </html>
@@ -0,0 +1,43 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>rotate (BitString)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/bitstring.rb, line 742</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rotate</span>(<span class="ruby-identifier">bits_p</span>)
15
+ <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">bounded?</span>)
16
+ <span class="ruby-identifier">_raise</span>(<span class="ruby-constant">UnboundedNonsense</span>,
17
+ <span class="ruby-value str">'rotation only applies to bounded bitstrings'</span>)
18
+ <span class="ruby-keyword kw">end</span>
19
+
20
+ <span class="ruby-identifier">value</span> = <span class="ruby-ivar">@value</span>
21
+ <span class="ruby-identifier">length</span> = <span class="ruby-ivar">@length</span>
22
+ <span class="ruby-identifier">bits</span> = <span class="ruby-identifier">bits_p</span>.<span class="ruby-identifier">to_i</span>.<span class="ruby-identifier">abs</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">length</span>
23
+ <span class="ruby-identifier">mask</span> = (<span class="ruby-identifier">mult</span> = <span class="ruby-value">2</span><span class="ruby-operator">**</span><span class="ruby-identifier">bits</span>) <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
24
+ <span class="ruby-identifier">ldiff</span> = <span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">bits</span>
25
+ <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">bits_p</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>)
26
+ <span class="ruby-comment cmt">#</span>
27
+ <span class="ruby-comment cmt"># Rotate right (toward the LSB)</span>
28
+ <span class="ruby-comment cmt">#</span>
29
+ <span class="ruby-identifier">residue</span> = <span class="ruby-identifier">value</span> <span class="ruby-operator">&amp;</span> <span class="ruby-identifier">mask</span>
30
+ <span class="ruby-identifier">value</span> <span class="ruby-operator">/=</span> <span class="ruby-identifier">mult</span>
31
+ <span class="ruby-identifier">value</span> <span class="ruby-operator">|=</span> <span class="ruby-identifier">residue</span> <span class="ruby-operator">*</span> <span class="ruby-value">2</span><span class="ruby-operator">**</span><span class="ruby-identifier">ldiff</span>
32
+ <span class="ruby-keyword kw">elsif</span> (<span class="ruby-identifier">bits_p</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>)
33
+ <span class="ruby-comment cmt">#</span>
34
+ <span class="ruby-comment cmt"># Rotate left (toward the MSB)</span>
35
+ <span class="ruby-comment cmt">#</span>
36
+ <span class="ruby-identifier">mask</span> <span class="ruby-operator">*=</span> <span class="ruby-value">2</span><span class="ruby-operator">**</span><span class="ruby-identifier">ldiff</span>
37
+ <span class="ruby-identifier">residue</span> = <span class="ruby-identifier">value</span> <span class="ruby-operator">&amp;</span> <span class="ruby-identifier">mask</span>
38
+ <span class="ruby-identifier">value</span> = ((<span class="ruby-identifier">value</span> <span class="ruby-operator">&amp;</span> <span class="ruby-operator">~</span><span class="ruby-identifier">mask</span>) <span class="ruby-operator">*</span> <span class="ruby-identifier">mult</span>) <span class="ruby-operator">|</span> (<span class="ruby-identifier">residue</span> <span class="ruby-operator">/</span> <span class="ruby-value">2</span><span class="ruby-operator">**</span><span class="ruby-identifier">ldiff</span>)
39
+ <span class="ruby-keyword kw">end</span>
40
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">value</span>, <span class="ruby-ivar">@length</span>)
41
+ <span class="ruby-keyword kw">end</span></pre>
42
+ </body>
43
+ </html>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>rotate! (BitString)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/bitstring.rb, line 786</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rotate!</span>(<span class="ruby-identifier">bits_p</span>)
15
+ <span class="ruby-ivar">@value</span> = <span class="ruby-identifier">rotate</span>(<span class="ruby-identifier">bits_p</span>).<span class="ruby-identifier">to_i</span>
16
+ <span class="ruby-keyword kw">self</span>
17
+ <span class="ruby-keyword kw">end</span></pre>
18
+ </body>
19
+ </html>
@@ -0,0 +1,40 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>shrink (BitString)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/bitstring.rb, line 809</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">shrink</span>(<span class="ruby-identifier">bits</span>=<span class="ruby-value">1</span>, <span class="ruby-identifier">direction</span>=<span class="ruby-constant">HIGH_END</span>)
15
+ <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">bits</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Integer</span>))
16
+ <span class="ruby-identifier">_raise</span>(<span class="ruby-constant">BitsRInts</span>)
17
+ <span class="ruby-keyword kw">end</span>
18
+ <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">bits</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-value">0</span>)
19
+ <span class="ruby-identifier">_raise</span>(<span class="ruby-constant">NoDeficitBits</span>)
20
+ <span class="ruby-keyword kw">end</span>
21
+ <span class="ruby-keyword kw">unless</span> ([<span class="ruby-constant">HIGH_END</span>, <span class="ruby-constant">LOW_END</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">direction</span>))
22
+ <span class="ruby-identifier">_raise</span>(<span class="ruby-constant">NeedGPS</span>)
23
+ <span class="ruby-keyword kw">end</span>
24
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">dup</span> <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">bits</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>)
25
+
26
+ <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">bounded?</span> <span class="ruby-operator">&amp;&amp;</span> (<span class="ruby-identifier">bits</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-ivar">@length</span>))
27
+ <span class="ruby-identifier">_raise</span>(<span class="ruby-constant">RuntimeError</span>, <span class="ruby-value str">'shrink count greater than bitstring size'</span>)
28
+ <span class="ruby-keyword kw">end</span>
29
+ <span class="ruby-identifier">value</span> = <span class="ruby-ivar">@value</span>
30
+ <span class="ruby-identifier">length</span> = <span class="ruby-identifier">bounded?</span> <span class="ruby-value">? </span><span class="ruby-ivar">@length</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">bits</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span>
31
+ <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">direction</span> <span class="ruby-operator">==</span> <span class="ruby-constant">LOW_END</span>)
32
+ <span class="ruby-identifier">value</span> <span class="ruby-operator">/=</span> <span class="ruby-value">2</span><span class="ruby-operator">**</span><span class="ruby-identifier">bits</span>
33
+ <span class="ruby-keyword kw">else</span>
34
+ <span class="ruby-identifier">_raise</span>(<span class="ruby-constant">UnboundedNonsense</span>) <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">bounded?</span>)
35
+ <span class="ruby-identifier">value</span> <span class="ruby-operator">&amp;=</span> <span class="ruby-value">2</span><span class="ruby-operator">**</span><span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
36
+ <span class="ruby-keyword kw">end</span>
37
+ <span class="ruby-identifier">bounded?</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">value</span>, <span class="ruby-identifier">length</span>) <span class="ruby-operator">:</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">value</span>)
38
+ <span class="ruby-keyword kw">end</span></pre>
39
+ </body>
40
+ </html>