Fix rust_impl
This commit is contained in:
parent
fcb1d2ed04
commit
0e5f84c3bf
3 changed files with 35 additions and 18 deletions
22
rust_impl/Cargo.lock
generated
22
rust_impl/Cargo.lock
generated
|
@ -1,11 +1,6 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "RunLengthEncoding"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"structopt",
|
||||
]
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
|
@ -120,6 +115,13 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "run_length_encoding"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"structopt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.8.0"
|
||||
|
@ -128,9 +130,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
|||
|
||||
[[package]]
|
||||
name = "structopt"
|
||||
version = "0.3.21"
|
||||
version = "0.3.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c"
|
||||
checksum = "69b041cdcb67226aca307e6e7be44c8806423d83e018bd662360a93dabce4d71"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"lazy_static",
|
||||
|
@ -139,9 +141,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "structopt-derive"
|
||||
version = "0.4.14"
|
||||
version = "0.4.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90"
|
||||
checksum = "7813934aecf5f51a54775e00068c237de98489463968231a51746bbbc03f9c10"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro-error",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "RunLengthEncoding"
|
||||
name = "run_length_encoding"
|
||||
version = "0.1.0"
|
||||
authors = ["Stephen Seo <seo.disparate@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
@ -7,4 +7,4 @@ edition = "2018"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
structopt = "0.3.21"
|
||||
structopt = "0.3.22"
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use structopt::StructOpt;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
#[structopt(name = "RunLengthEncoding")]
|
||||
|
@ -10,13 +9,29 @@ struct Opts {
|
|||
fn main() {
|
||||
let opts = Opts::from_args();
|
||||
|
||||
let mut map: HashMap<char, u32> = HashMap::new();
|
||||
|
||||
let mut current: Option<char> = None;
|
||||
let mut current_count: u32 = 0;
|
||||
let mut list: Vec<(char, u32)> = Vec::new();
|
||||
for c in opts.input.chars() {
|
||||
map.get_mut(&c).map(|v| *v += 1).or_else(|| {map.insert(c, 1); Some(())});
|
||||
if c.is_ascii_whitespace() {
|
||||
continue;
|
||||
} else {
|
||||
if current.is_none() || current.unwrap() != c {
|
||||
if current_count > 0 {
|
||||
list.push((current.unwrap(), current_count));
|
||||
}
|
||||
current_count = 1;
|
||||
current = Some(c);
|
||||
} else {
|
||||
current_count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if current_count > 0 && current.is_some() {
|
||||
list.push((current.unwrap(), current_count));
|
||||
}
|
||||
|
||||
for (c, value) in map {
|
||||
println!("{} with value {}", c, value);
|
||||
for (c, count) in list {
|
||||
println!("{}: has count of {}", c, count);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue