Skip to content

Commit 1aac00f

Browse files
committed
---
yaml --- r: 14756 b: refs/heads/try c: 95521c4 h: refs/heads/master v: v3
1 parent 1ee2fb7 commit 1aac00f

27 files changed

+709
-1566
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: b22556a6f818845cd400ad58065a83916ba591a7
5+
refs/heads/try: 95521c408438efc5794e83953086c812b795c756
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/libstd/bitv.rs

Lines changed: 47 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
/*
2-
Module: bitv
3-
4-
Bitvectors.
5-
*/
6-
71
export t;
82
export create;
93
export union;
@@ -28,25 +22,19 @@ export eq_vec;
2822
// an optimizing version of this module that produces a different obj
2923
// for the case where nbits <= 32.
3024

31-
/*
32-
Type: t
33-
34-
The bitvector type.
35-
*/
25+
#[doc = "The bitvector type"]
3626
type t = @{storage: [mutable uint], nbits: uint};
3727

38-
3928
const uint_bits: uint = 32u + (1u << 32u >> 27u);
4029

41-
/*
42-
Function: create
30+
#[doc = "
31+
Constructs a bitvector
4332
44-
Constructs a bitvector.
33+
# Arguments
4534
46-
Parameters:
47-
nbits - The number of bits in the bitvector
48-
init - If true then the bits are initialized to 1, otherwise 0
49-
*/
35+
* nbits - The number of bits in the bitvector
36+
* init - If true then the bits are initialized to 1, otherwise 0
37+
"]
5038
fn create(nbits: uint, init: bool) -> t {
5139
let elt = if init { !0u } else { 0u };
5240
let storage = vec::to_mut(vec::init_elt(nbits / uint_bits + 1u, elt));
@@ -74,60 +62,35 @@ fn union(v0: t, v1: t) -> bool { let sub = lor; ret process(v0, v1, sub); }
7462

7563
fn land(w0: uint, w1: uint) -> uint { ret w0 & w1; }
7664

77-
/*
78-
Function: intersect
79-
65+
#[doc = "
8066
Calculates the intersection of two bitvectors
8167
82-
Sets `v0` to the intersection of `v0` and `v1`
83-
84-
Preconditions:
85-
86-
Both bitvectors must be the same length
87-
88-
Returns:
89-
90-
True if `v0` was changed
91-
*/
68+
Sets `v0` to the intersection of `v0` and `v1`. Both bitvectors must be the
69+
same length. Returns 'true' if `v0` was changed.
70+
"]
9271
fn intersect(v0: t, v1: t) -> bool {
9372
let sub = land;
9473
ret process(v0, v1, sub);
9574
}
9675

9776
fn right(_w0: uint, w1: uint) -> uint { ret w1; }
9877

99-
/*
100-
Function: assign
101-
78+
#[doc = "
10279
Assigns the value of `v1` to `v0`
10380
104-
Preconditions:
105-
106-
Both bitvectors must be the same length
107-
108-
Returns:
109-
110-
True if `v0` was changed
111-
*/
81+
Both bitvectors must be the same length. Returns `true` if `v0` was changed
82+
"]
11283
fn assign(v0: t, v1: t) -> bool { let sub = right; ret process(v0, v1, sub); }
11384

114-
/*
115-
Function: clone
116-
117-
Makes a copy of a bitvector
118-
*/
85+
#[doc = "Makes a copy of a bitvector"]
11986
fn clone(v: t) -> t {
12087
let storage = vec::to_mut(vec::init_elt(v.nbits / uint_bits + 1u, 0u));
12188
let len = vec::len(v.storage);
12289
uint::range(0u, len) {|i| storage[i] = v.storage[i]; };
12390
ret @{storage: storage, nbits: v.nbits};
12491
}
12592

126-
/*
127-
Function: get
128-
129-
Retreive the value at index `i`
130-
*/
93+
#[doc = "Retreive the value at index `i`"]
13194
pure fn get(v: t, i: uint) -> bool {
13295
assert (i < v.nbits);
13396
let bits = uint_bits;
@@ -139,19 +102,12 @@ pure fn get(v: t, i: uint) -> bool {
139102

140103
// FIXME: This doesn't account for the actual size of the vectors,
141104
// so it could end up comparing garbage bits
142-
/*
143-
Function: equal
144-
105+
#[doc = "
145106
Compares two bitvectors
146107
147-
Preconditions:
148-
149-
Both bitvectors must be the same length
150-
151-
Returns:
152-
153-
True if both bitvectors contain identical elements
154-
*/
108+
Both bitvectors must be the same length. Returns `true` if both bitvectors
109+
contain identical elements.
110+
"]
155111
fn equal(v0: t, v1: t) -> bool {
156112
// FIXME: when we can break or return from inside an iterator loop,
157113
// we can eliminate this painful while-loop
@@ -165,67 +121,43 @@ fn equal(v0: t, v1: t) -> bool {
165121
ret true;
166122
}
167123

168-
/*
169-
Function: clear
170-
171-
Set all bits to 0
172-
*/
124+
#[doc = "Set all bits to 0"]
173125
fn clear(v: t) {
174126
uint::range(0u, vec::len(v.storage)) {|i| v.storage[i] = 0u; };
175127
}
176128

177-
/*
178-
Function: set_all
179-
180-
Set all bits to 1
181-
*/
129+
#[doc = "Set all bits to 1"]
182130
fn set_all(v: t) {
183131
uint::range(0u, v.nbits) {|i| set(v, i, true); };
184132
}
185133

186-
/*
187-
Function: invert
188-
189-
Invert all bits
190-
*/
134+
#[doc = "Invert all bits"]
191135
fn invert(v: t) {
192136
uint::range(0u, vec::len(v.storage)) {|i|
193137
v.storage[i] = !v.storage[i];
194138
};
195139
}
196140

197-
/*
198-
Function: difference
199-
141+
#[doc = "
200142
Calculate the difference between two bitvectors
201143
202144
Sets each element of `v0` to the value of that element minus the element
203-
of `v1` at the same index.
204-
205-
Preconditions:
206-
207-
Both bitvectors must be the same length
145+
of `v1` at the same index. Both bitvectors must be the same length.
208146
209-
Returns:
210-
211-
True if `v0` was changed
212-
*/
147+
Returns `true` if `v0` was changed.
148+
"]
213149
fn difference(v0: t, v1: t) -> bool {
214150
invert(v1);
215151
let b = intersect(v0, v1);
216152
invert(v1);
217153
ret b;
218154
}
219155

220-
/*
221-
Function: set
222-
156+
#[doc = "
223157
Set the value of a bit at a given index
224158
225-
Preconditions:
226-
227-
`i` must be less than the length of the bitvector
228-
*/
159+
`i` must be less than the length of the bitvector.
160+
"]
229161
fn set(v: t, i: uint, x: bool) {
230162
assert (i < v.nbits);
231163
let bits = uint_bits;
@@ -236,62 +168,50 @@ fn set(v: t, i: uint, x: bool) {
236168
}
237169

238170

239-
/*
240-
Function: is_true
241-
242-
Returns true if all bits are 1
243-
*/
171+
#[doc = "Returns true if all bits are 1"]
244172
fn is_true(v: t) -> bool {
245173
for i: uint in to_vec(v) { if i != 1u { ret false; } }
246174
ret true;
247175
}
248176

249177

250-
/*
251-
Function: is_false
252-
253-
Returns true if all bits are 0
254-
*/
178+
#[doc = "Returns true if all bits are 0"]
255179
fn is_false(v: t) -> bool {
256180
for i: uint in to_vec(v) { if i == 1u { ret false; } }
257181
ret true;
258182
}
259183

260184
fn init_to_vec(v: t, i: uint) -> uint { ret if get(v, i) { 1u } else { 0u }; }
261185

262-
/*
263-
Function: to_vec
186+
#[doc = "
187+
Converts the bitvector to a vector of uint with the same length.
264188
265-
Converts the bitvector to a vector of uint with the same length. Each uint
266-
in the resulting vector has either value 0u or 1u.
267-
*/
189+
Each uint in the resulting vector has either value 0u or 1u.
190+
"]
268191
fn to_vec(v: t) -> [uint] {
269192
let sub = bind init_to_vec(v, _);
270193
ret vec::init_fn::<uint>(v.nbits, sub);
271194
}
272195

273-
/*
274-
Function: to_str
275196

276-
Converts the bitvector to a string. The resulting string has the same
277-
length as the bitvector, and each character is either '0' or '1'.
278-
*/
197+
#[doc = "
198+
Converts the bitvector to a string.
199+
200+
The resulting string has the same length as the bitvector, and each character
201+
is either '0' or '1'.
202+
"]
279203
fn to_str(v: t) -> str {
280204
let rs = "";
281205
for i: uint in to_vec(v) { if i == 1u { rs += "1"; } else { rs += "0"; } }
282206
ret rs;
283207
}
284208

285-
/*
286-
Function: eq_vec
287-
288-
Compare a bitvector to a vector of uint. The uint vector is expected to
289-
only contain the values 0u and 1u.
290-
291-
Preconditions:
209+
#[doc = "
210+
Compare a bitvector to a vector of uint
292211
293-
Both the bitvector and vector must have the same length
294-
*/
212+
The uint vector is expected to only contain the values 0u and 1u. Both the
213+
bitvector and vector must have the same length
214+
"]
295215
fn eq_vec(v0: t, v1: [uint]) -> bool {
296216
assert (v0.nbits == vec::len::<uint>(v1));
297217
let len = v0.nbits;

0 commit comments

Comments
 (0)