1
Fork 0
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:
Michael Gehring 2014-05-18 21:42:25 +02:00
parent 1718fbe72c
commit 91b9b4b441

View file

@ -12,7 +12,8 @@
extern crate collections;
extern crate getopts;
use collections::hashmap::{HashMap, HashSet};
use collections::hashmap::HashSet;
use collections::smallintmap::SmallIntMap;
use getopts::OptGroup;
use std::char::from_u32;
use std::io::print;
@ -99,21 +100,21 @@ fn delete(set: Vec<char>) {
}
fn tr(set1: &[char], set2: &[char]) {
let mut map = HashMap::new();
let mut map = SmallIntMap::<char>::new();
let mut out = stdout();
for i in range(0, set1.len()) {
if i >= set2.len() {
map.insert(set1[i], set2[set2.len()-1]);
map.insert(set1[i] as uint, set2[set2.len()-1]);
} else {
map.insert(set1[i], set2[i]);
map.insert(set1[i] as uint, set2[i]);
}
}
for c in stdin().chars() {
match c {
Ok(inc) => {
let trc = match map.find(&inc) {
let trc = match map.find(&(inc as uint)) {
Some(t) => *t,
None => inc,
};