Skip to content

Commit 4ea65ed

Browse files
committed
---
yaml --- r: 551 b: refs/heads/master c: 9fc4fc6 h: refs/heads/master i: 549: 2d45eb8 547: 5bb0482 543: 0b4eb4a v: v3
1 parent a13ddb1 commit 4ea65ed

File tree

7 files changed

+76
-61
lines changed

7 files changed

+76
-61
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: 5f9750ca2c0c7ae744f35ec0949527f106c10099
2+
refs/heads/master: 9fc4fc6692c6684487eb57c6608ee34ab94dd9f5

trunk/src/lib/_int.rs

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -25,66 +25,12 @@ iter range(mutable int lo, int hi) -> int {
2525
}
2626
}
2727

28-
iter urange(mutable uint lo, uint hi) -> uint {
29-
while (lo < hi) {
30-
put lo;
31-
lo += 1u;
32-
}
33-
}
34-
35-
fn next_power_of_two(uint n) -> uint {
36-
// FIXME change |* uint(4)| below to |* uint(8) / uint(2)| and watch the
37-
// world explode.
38-
let uint halfbits = sys.rustrt.size_of[uint]() * 4u;
39-
let uint tmp = n - 1u;
40-
let uint shift = 1u;
41-
while (shift <= halfbits) {
42-
tmp |= tmp >> shift;
43-
shift <<= 1u;
44-
}
45-
ret tmp + 1u;
46-
}
47-
48-
fn uto_str(mutable uint n, uint radix) -> str
49-
{
50-
check (0u < radix && radix <= 16u);
51-
fn digit(uint n) -> str {
52-
alt (n) {
53-
case (0u) { ret "0"; }
54-
case (1u) { ret "1"; }
55-
case (2u) { ret "2"; }
56-
case (3u) { ret "3"; }
57-
case (4u) { ret "4"; }
58-
case (5u) { ret "5"; }
59-
case (6u) { ret "6"; }
60-
case (7u) { ret "7"; }
61-
case (8u) { ret "8"; }
62-
case (9u) { ret "9"; }
63-
case (10u) { ret "a"; }
64-
case (11u) { ret "b"; }
65-
case (12u) { ret "c"; }
66-
case (13u) { ret "d"; }
67-
case (14u) { ret "e"; }
68-
case (15u) { ret "f"; }
69-
}
70-
}
71-
72-
if (n == 0u) { ret "0"; }
73-
74-
let str s = "";
75-
while (n > 0u) {
76-
s = digit(n % radix) + s;
77-
n /= radix;
78-
}
79-
ret s;
80-
}
81-
8228
fn to_str(mutable int n, uint radix) -> str
8329
{
8430
check (0u < radix && radix <= 16u);
8531
if (n < 0) {
86-
ret "-" + uto_str((-n) as uint, radix);
32+
ret "-" + _uint.to_str((-n) as uint, radix);
8733
} else {
88-
ret uto_str(n as uint, radix);
34+
ret _uint.to_str(n as uint, radix);
8935
}
9036
}

trunk/src/lib/_io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn file_writer(str path,
146146
unsafe obj fw(buf_writer out) {
147147
fn write_str(str s) { out.write(_str.bytes(s)); }
148148
fn write_int(int n) { out.write(_str.bytes(_int.to_str(n, 10u))); }
149-
fn write_uint(uint n) { out.write(_str.bytes(_int.uto_str(n, 10u))); }
149+
fn write_uint(uint n) { out.write(_str.bytes(_uint.to_str(n, 10u))); }
150150
}
151151
ret fw(new_buf_writer(path, flags));
152152
}

trunk/src/lib/_uint.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import std.sys;
2+
3+
fn add(uint x, uint y) -> uint { ret x + y; }
4+
fn sub(uint x, uint y) -> uint { ret x - y; }
5+
fn mul(uint x, uint y) -> uint { ret x * y; }
6+
fn div(uint x, uint y) -> uint { ret x / y; }
7+
fn rem(uint x, uint y) -> uint { ret x % y; }
8+
9+
fn lt(uint x, uint y) -> bool { ret x < y; }
10+
fn le(uint x, uint y) -> bool { ret x <= y; }
11+
fn eq(uint x, uint y) -> bool { ret x == y; }
12+
fn ne(uint x, uint y) -> bool { ret x != y; }
13+
fn ge(uint x, uint y) -> bool { ret x >= y; }
14+
fn gt(uint x, uint y) -> bool { ret x > y; }
15+
16+
iter range(mutable uint lo, uint hi) -> uint {
17+
while (lo < hi) {
18+
put lo;
19+
lo += 1u;
20+
}
21+
}
22+
23+
fn next_power_of_two(uint n) -> uint {
24+
// FIXME change |* uint(4)| below to |* uint(8) / uint(2)| and watch the
25+
// world explode.
26+
let uint halfbits = sys.rustrt.size_of[uint]() * 4u;
27+
let uint tmp = n - 1u;
28+
let uint shift = 1u;
29+
while (shift <= halfbits) {
30+
tmp |= tmp >> shift;
31+
shift <<= 1u;
32+
}
33+
ret tmp + 1u;
34+
}
35+
36+
fn to_str(mutable uint n, uint radix) -> str
37+
{
38+
check (0u < radix && radix <= 16u);
39+
fn digit(uint n) -> str {
40+
alt (n) {
41+
case (0u) { ret "0"; }
42+
case (1u) { ret "1"; }
43+
case (2u) { ret "2"; }
44+
case (3u) { ret "3"; }
45+
case (4u) { ret "4"; }
46+
case (5u) { ret "5"; }
47+
case (6u) { ret "6"; }
48+
case (7u) { ret "7"; }
49+
case (8u) { ret "8"; }
50+
case (9u) { ret "9"; }
51+
case (10u) { ret "a"; }
52+
case (11u) { ret "b"; }
53+
case (12u) { ret "c"; }
54+
case (13u) { ret "d"; }
55+
case (14u) { ret "e"; }
56+
case (15u) { ret "f"; }
57+
}
58+
}
59+
60+
if (n == 0u) { ret "0"; }
61+
62+
let str s = "";
63+
while (n > 0u) {
64+
s = digit(n % radix) + s;
65+
n /= radix;
66+
}
67+
ret s;
68+
}

trunk/src/lib/deque.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn create[T]() -> t[T] {
4242
}
4343
}
4444

45-
let uint nalloc = _int.next_power_of_two(nelts + 1u);
45+
let uint nalloc = _uint.next_power_of_two(nelts + 1u);
4646
let _vec.init_op[cell[T]] copy_op = bind fill[T](_, nelts, lo, elts);
4747
ret _vec.init_fn[cell[T]](copy_op, nalloc);
4848
}

trunk/src/lib/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
145145
fn insert(&K key, &V val) -> bool {
146146
let util.rational load = rec(num=(nelts + 1u) as int, den=nbkts as int);
147147
if (!util.rational_leq(load, lf)) {
148-
let uint nnewbkts = _int.next_power_of_two(nbkts + 1u);
148+
let uint nnewbkts = _uint.next_power_of_two(nbkts + 1u);
149149

150150
let vec[mutable bucket[K, V]] newbkts = make_buckets[K, V](nnewbkts);
151151
rehash[K, V](hasher, eqer, bkts, nbkts, newbkts, nnewbkts);

trunk/src/lib/std.rc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ meta (name = "std",
77
// Built-in types support modules.
88

99
mod _int;
10+
mod _uint;
1011
mod _u8;
1112
mod _vec;
1213
mod _str;
@@ -28,7 +29,7 @@ auth _str = unsafe;
2829
auth _vec = unsafe;
2930
auth _task = unsafe;
3031

31-
auth _int.next_power_of_two = unsafe;
32+
auth _uint.next_power_of_two = unsafe;
3233
auth map.mk_hashmap = unsafe;
3334
auth rand.mk_rng = unsafe;
3435

0 commit comments

Comments
 (0)