Convert std::u64 to istrs. Issue #855
This commit is contained in:
parent
53be480d20
commit
8146ca982e
@ -1,36 +1,36 @@
|
||||
fn to_str(n: u64, radix: uint) -> str {
|
||||
fn to_str(n: u64, radix: uint) -> istr {
|
||||
assert (0u < radix && radix <= 16u);
|
||||
|
||||
let r64 = radix as u64;
|
||||
|
||||
fn digit(n: u64) -> str {
|
||||
fn digit(n: u64) -> istr {
|
||||
ret alt n {
|
||||
0u64 { "0" }
|
||||
1u64 { "1" }
|
||||
2u64 { "2" }
|
||||
3u64 { "3" }
|
||||
4u64 { "4" }
|
||||
5u64 { "5" }
|
||||
6u64 { "6" }
|
||||
7u64 { "7" }
|
||||
8u64 { "8" }
|
||||
9u64 { "9" }
|
||||
10u64 { "a" }
|
||||
11u64 { "b" }
|
||||
12u64 { "c" }
|
||||
13u64 { "d" }
|
||||
14u64 { "e" }
|
||||
15u64 { "f" }
|
||||
0u64 { ~"0" }
|
||||
1u64 { ~"1" }
|
||||
2u64 { ~"2" }
|
||||
3u64 { ~"3" }
|
||||
4u64 { ~"4" }
|
||||
5u64 { ~"5" }
|
||||
6u64 { ~"6" }
|
||||
7u64 { ~"7" }
|
||||
8u64 { ~"8" }
|
||||
9u64 { ~"9" }
|
||||
10u64 { ~"a" }
|
||||
11u64 { ~"b" }
|
||||
12u64 { ~"c" }
|
||||
13u64 { ~"d" }
|
||||
14u64 { ~"e" }
|
||||
15u64 { ~"f" }
|
||||
_ { fail }
|
||||
};
|
||||
}
|
||||
|
||||
if n == 0u64 { ret "0"; }
|
||||
if n == 0u64 { ret ~"0"; }
|
||||
|
||||
let s = "";
|
||||
let s = ~"";
|
||||
|
||||
while n > 0u64 { s = digit(n % r64) + s; n /= r64; }
|
||||
ret s;
|
||||
}
|
||||
|
||||
fn str(n: u64) -> str { ret to_str(n, 10u); }
|
||||
fn str(n: u64) -> istr { ret to_str(n, 10u); }
|
||||
|
@ -15,6 +15,7 @@ import std::vec;
|
||||
import std::uint;
|
||||
import std::time;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
import std::int::range;
|
||||
import std::io;
|
||||
import std::getopts;
|
||||
@ -106,7 +107,7 @@ fn main(argv: [str]) {
|
||||
let elapsed = stop - start;
|
||||
|
||||
out.write_line(#fmt["%d\t%d\t%s", n, fibn,
|
||||
u64::str(elapsed)]);
|
||||
istr::to_estr(u64::str(elapsed))]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import option = std::option::t;
|
||||
import std::option::some;
|
||||
import std::option::none;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
import std::treemap;
|
||||
import std::vec;
|
||||
import std::io;
|
||||
@ -226,7 +227,8 @@ fn main(argv: [str]) {
|
||||
let elapsed = stop - start;
|
||||
elapsed /= 1000000u64;
|
||||
|
||||
log_err "MapReduce completed in " + u64::str(elapsed) + "ms";
|
||||
log_err "MapReduce completed in " +
|
||||
istr::to_estr(u64::str(elapsed)) + "ms";
|
||||
}
|
||||
|
||||
fn read_word(r: io::reader) -> option<str> {
|
||||
|
@ -216,7 +216,7 @@ fn main(argv: [str]) {
|
||||
let elapsed = stop - start;
|
||||
elapsed /= 1000000u64;
|
||||
|
||||
log_err "MapReduce completed in " + u64::str(elapsed) + "ms";
|
||||
log_err ~"MapReduce completed in " + u64::str(elapsed) + ~"ms";
|
||||
}
|
||||
|
||||
fn read_word(r: io::reader) -> option<str> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user