mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
tr: use SmallIntMap instead of HashMap
This commit is contained in:
parent
1718fbe72c
commit
91b9b4b441
1 changed files with 6 additions and 5 deletions
11
tr/tr.rs
11
tr/tr.rs
|
@ -12,7 +12,8 @@
|
||||||
extern crate collections;
|
extern crate collections;
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
|
|
||||||
use collections::hashmap::{HashMap, HashSet};
|
use collections::hashmap::HashSet;
|
||||||
|
use collections::smallintmap::SmallIntMap;
|
||||||
use getopts::OptGroup;
|
use getopts::OptGroup;
|
||||||
use std::char::from_u32;
|
use std::char::from_u32;
|
||||||
use std::io::print;
|
use std::io::print;
|
||||||
|
@ -99,21 +100,21 @@ fn delete(set: Vec<char>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tr(set1: &[char], set2: &[char]) {
|
fn tr(set1: &[char], set2: &[char]) {
|
||||||
let mut map = HashMap::new();
|
let mut map = SmallIntMap::<char>::new();
|
||||||
let mut out = stdout();
|
let mut out = stdout();
|
||||||
|
|
||||||
for i in range(0, set1.len()) {
|
for i in range(0, set1.len()) {
|
||||||
if i >= set2.len() {
|
if i >= set2.len() {
|
||||||
map.insert(set1[i], set2[set2.len()-1]);
|
map.insert(set1[i] as uint, set2[set2.len()-1]);
|
||||||
} else {
|
} else {
|
||||||
map.insert(set1[i], set2[i]);
|
map.insert(set1[i] as uint, set2[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for c in stdin().chars() {
|
for c in stdin().chars() {
|
||||||
match c {
|
match c {
|
||||||
Ok(inc) => {
|
Ok(inc) => {
|
||||||
let trc = match map.find(&inc) {
|
let trc = match map.find(&(inc as uint)) {
|
||||||
Some(t) => *t,
|
Some(t) => *t,
|
||||||
None => inc,
|
None => inc,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue