Skip to content

Commit c3b894e

Browse files
mbrubeckbrson
authored andcommitted
---
yaml --- r: 5980 b: refs/heads/master c: 50d99ec h: refs/heads/master v: v3
1 parent feb92a8 commit c3b894e

File tree

2 files changed

+74
-11
lines changed

2 files changed

+74
-11
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: a9f9227a1c3d944ea9f5d88c721fbb32473b5454
2+
refs/heads/master: 50d99ec32ce197fb3c355d7cd88ace82e538790e

trunk/src/lib/uint.rs

Lines changed: 73 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,78 @@
1-
/**
2-
* Return the minimal value for an uint.
3-
*
4-
* This is always 0
5-
*/
1+
/*
2+
Module: uint
3+
*/
4+
5+
/*
6+
Function: min_value
7+
8+
Return the minimal value for an uint.
9+
10+
This is always 0
11+
*/
612
pure fn min_value() -> uint { ret 0u; }
713

8-
/**
9-
* Return the maximal value for an uint.
10-
*
11-
* This is 2^wordsize - 1
12-
*/
14+
/*
15+
Function: max_value
16+
17+
Return the maximal value for an uint.
18+
19+
This is 2^wordsize - 1
20+
*/
1321
pure fn max_value() -> uint {
1422
ret 0u - 1u;
1523
}
1624

25+
/* Function: add */
1726
pure fn add(x: uint, y: uint) -> uint { ret x + y; }
1827

28+
/* Function: sub */
1929
pure fn sub(x: uint, y: uint) -> uint { ret x - y; }
2030

31+
/* Function: mul */
2132
pure fn mul(x: uint, y: uint) -> uint { ret x * y; }
2233

34+
/* Function: div */
2335
pure fn div(x: uint, y: uint) -> uint { ret x / y; }
2436

37+
/* Function: rem */
2538
pure fn rem(x: uint, y: uint) -> uint { ret x % y; }
2639

40+
/* Predicate: lt */
2741
pure fn lt(x: uint, y: uint) -> bool { ret x < y; }
2842

43+
/* Predicate: le */
2944
pure fn le(x: uint, y: uint) -> bool { ret x <= y; }
3045

46+
/* Predicate: eq */
3147
pure fn eq(x: uint, y: uint) -> bool { ret x == y; }
3248

49+
/* Predicate: ne */
3350
pure fn ne(x: uint, y: uint) -> bool { ret x != y; }
3451

52+
/* Predicate: ge */
3553
pure fn ge(x: uint, y: uint) -> bool { ret x >= y; }
3654

55+
/* Predicate: gt */
3756
pure fn gt(x: uint, y: uint) -> bool { ret x > y; }
3857

3958
fn max(x: uint, y: uint) -> uint { if x > y { ret x; } ret y; }
4059

4160
fn min(x: uint, y: uint) -> uint { if x > y { ret y; } ret x; }
4261

62+
/*
63+
Function: range
64+
65+
Iterate over the range [`lo`..`hi`)
66+
*/
4367
fn range(lo: uint, hi: uint, it: block(uint)) {
4468
while lo < hi { it(lo); lo += 1u; }
4569
}
4670

71+
/*
72+
Function: next_power_of_two
73+
74+
Returns the smallest power of 2 greater than or equal to `n`
75+
*/
4776
fn next_power_of_two(n: uint) -> uint {
4877
let halfbits: uint = sys::size_of::<uint>() * 4u;
4978
let tmp: uint = n - 1u;
@@ -52,6 +81,20 @@ fn next_power_of_two(n: uint) -> uint {
5281
ret tmp + 1u;
5382
}
5483

84+
/*
85+
Function: parse_buf
86+
87+
Parse a buffer of bytes
88+
89+
Parameters:
90+
91+
buf - A byte buffer
92+
radix - The base of the number
93+
94+
Failure:
95+
96+
buf must not be empty
97+
*/
5598
fn parse_buf(buf: [u8], radix: uint) -> uint {
5699
if vec::len::<u8>(buf) == 0u {
57100
log_err "parse_buf(): buf is empty";
@@ -69,8 +112,22 @@ fn parse_buf(buf: [u8], radix: uint) -> uint {
69112
fail;
70113
}
71114

115+
/*
116+
Function: from_str
117+
118+
Parse a string to an int
119+
120+
Failure:
121+
122+
s must not be empty
123+
*/
72124
fn from_str(s: str) -> uint { parse_buf(str::bytes(s), 10u) }
73125

126+
/*
127+
Function: to_str
128+
129+
Convert to a string in a given base
130+
*/
74131
fn to_str(num: uint, radix: uint) -> str {
75132
let n = num;
76133
assert (0u < radix && radix <= 16u);
@@ -106,6 +163,12 @@ fn to_str(num: uint, radix: uint) -> str {
106163
while len != 0u { len -= 1u; s1 += str::unsafe_from_byte(s[len]); }
107164
ret s1;
108165
}
166+
167+
/*
168+
Function: str
169+
170+
Convert to a string
171+
*/
109172
fn str(i: uint) -> str { ret to_str(i, 10u); }
110173

111174
// Local Variables:

0 commit comments

Comments
 (0)