Pure Programmer
Blue Matrix


Cluster Map

Project: Frequency Table (Bytes)

Write a program to generate a table of frequencies. The program should accept a stream on stdin and total the number of each byte seen. Once the stream has been read the program should print a tab-delimited table with columns for Byte Value (decimal), Byte Value (hexadecimal), Count, and Frequency. The frequency of each byte is the count for that byte divided by the total number of bytes in the file. Only print rows in the table for values with a byte count greater than 0.

Output
$ rustc FrequencyTableBytes.rs error: unknown format trait `d` --> FrequencyTableBytes.rs:34:32 | 34 | println!("{}", format!("{0:d}\t{0:02x}\t{1:d}\t{2:.4f}", x, countTable[x], freq)); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `d` --> FrequencyTableBytes.rs:34:48 | 34 | println!("{}", format!("{0:d}\t{0:02x}\t{1:d}\t{2:.4f}", x, countTable[x], freq)); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `f` --> FrequencyTableBytes.rs:34:57 | 34 | println!("{}", format!("{0:d}\t{0:02x}\t{1:d}\t{2:.4f}", x, countTable[x], freq)); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error[E0425]: cannot find value `cin` in this scope --> FrequencyTableBytes.rs:21:10 | 21 | binmode(cin); | ^^^ not found in this scope error[E0277]: the type `[isize]` cannot be indexed by `isize` --> FrequencyTableBytes.rs:16:15 | 16 | countTable[x] = 0; | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<isize>` error[E0425]: cannot find function `binmode` in this scope --> FrequencyTableBytes.rs:21:2 | 21 | binmode(cin); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `getbyte` in this scope --> FrequencyTableBytes.rs:23:8 | 23 | while getbyte(c) { | ^^^^^^^ not found in this scope error[E0277]: the type `[isize]` cannot be indexed by `u8` --> FrequencyTableBytes.rs:24:14 | 24 | countTable[c] += 1; | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `u8` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<u8>` error[E0277]: the type `[isize]` cannot be indexed by `isize` --> FrequencyTableBytes.rs:32:18 | 32 | if countTable[x] > 0 { | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<isize>` error[E0277]: the type `[isize]` cannot be indexed by `isize` --> FrequencyTableBytes.rs:33:41 | 33 | let freq:f64 = f64::from(countTable[x]) / f64::from(totalCount); | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<isize>` error[E0277]: the trait bound `f64: From<isize>` is not satisfied --> FrequencyTableBytes.rs:33:57 | 33 | let freq:f64 = f64::from(countTable[x]) / f64::from(totalCount); | --------- ^^^^^^^^^^ the trait `From<isize>` is not implemented for `f64` | | | required by a bound introduced by this call | = help: the following other types implement trait `From<T>`: <f64 as From<bool>> <f64 as From<f32>> <f64 as From<i16>> <f64 as From<i32>> <f64 as From<i8>> <f64 as From<u16>> <f64 as From<u32>> <f64 as From<u8>> error[E0277]: the type `[isize]` cannot be indexed by `isize` --> FrequencyTableBytes.rs:34:76 | 34 | println!("{}", format!("{0:d}\t{0:02x}\t{1:d}\t{2:.4f}", x, countTable[x], freq)); | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<isize>` error: aborting due to 12 previous errors Some errors have detailed explanations: E0277, E0425. For more information about an error, try `rustc --explain E0277`. $ rustc FrequencyTableBytes.rs error: unknown format trait `d` --> FrequencyTableBytes.rs:34:32 | 34 | println!("{}", format!("{0:d}\t{0:02x}\t{1:d}\t{2:.4f}", x, countTable[x], freq)); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `d` --> FrequencyTableBytes.rs:34:48 | 34 | println!("{}", format!("{0:d}\t{0:02x}\t{1:d}\t{2:.4f}", x, countTable[x], freq)); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `f` --> FrequencyTableBytes.rs:34:57 | 34 | println!("{}", format!("{0:d}\t{0:02x}\t{1:d}\t{2:.4f}", x, countTable[x], freq)); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error[E0425]: cannot find value `cin` in this scope --> FrequencyTableBytes.rs:21:10 | 21 | binmode(cin); | ^^^ not found in this scope error[E0277]: the type `[isize]` cannot be indexed by `isize` --> FrequencyTableBytes.rs:16:15 | 16 | countTable[x] = 0; | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<isize>` error[E0425]: cannot find function `binmode` in this scope --> FrequencyTableBytes.rs:21:2 | 21 | binmode(cin); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `getbyte` in this scope --> FrequencyTableBytes.rs:23:8 | 23 | while getbyte(c) { | ^^^^^^^ not found in this scope error[E0277]: the type `[isize]` cannot be indexed by `u8` --> FrequencyTableBytes.rs:24:14 | 24 | countTable[c] += 1; | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `u8` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<u8>` error[E0277]: the type `[isize]` cannot be indexed by `isize` --> FrequencyTableBytes.rs:32:18 | 32 | if countTable[x] > 0 { | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<isize>` error[E0277]: the type `[isize]` cannot be indexed by `isize` --> FrequencyTableBytes.rs:33:41 | 33 | let freq:f64 = f64::from(countTable[x]) / f64::from(totalCount); | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<isize>` error[E0277]: the trait bound `f64: From<isize>` is not satisfied --> FrequencyTableBytes.rs:33:57 | 33 | let freq:f64 = f64::from(countTable[x]) / f64::from(totalCount); | --------- ^^^^^^^^^^ the trait `From<isize>` is not implemented for `f64` | | | required by a bound introduced by this call | = help: the following other types implement trait `From<T>`: <f64 as From<bool>> <f64 as From<f32>> <f64 as From<i16>> <f64 as From<i32>> <f64 as From<i8>> <f64 as From<u16>> <f64 as From<u32>> <f64 as From<u8>> error[E0277]: the type `[isize]` cannot be indexed by `isize` --> FrequencyTableBytes.rs:34:76 | 34 | println!("{}", format!("{0:d}\t{0:02x}\t{1:d}\t{2:.4f}", x, countTable[x], freq)); | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<isize>` error: aborting due to 12 previous errors Some errors have detailed explanations: E0277, E0425. For more information about an error, try `rustc --explain E0277`. $ rustc FrequencyTableBytes.rs error: unknown format trait `d` --> FrequencyTableBytes.rs:34:32 | 34 | println!("{}", format!("{0:d}\t{0:02x}\t{1:d}\t{2:.4f}", x, countTable[x], freq)); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `d` --> FrequencyTableBytes.rs:34:48 | 34 | println!("{}", format!("{0:d}\t{0:02x}\t{1:d}\t{2:.4f}", x, countTable[x], freq)); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `f` --> FrequencyTableBytes.rs:34:57 | 34 | println!("{}", format!("{0:d}\t{0:02x}\t{1:d}\t{2:.4f}", x, countTable[x], freq)); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error[E0425]: cannot find value `cin` in this scope --> FrequencyTableBytes.rs:21:10 | 21 | binmode(cin); | ^^^ not found in this scope error[E0277]: the type `[isize]` cannot be indexed by `isize` --> FrequencyTableBytes.rs:16:15 | 16 | countTable[x] = 0; | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<isize>` error[E0425]: cannot find function `binmode` in this scope --> FrequencyTableBytes.rs:21:2 | 21 | binmode(cin); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `getbyte` in this scope --> FrequencyTableBytes.rs:23:8 | 23 | while getbyte(c) { | ^^^^^^^ not found in this scope error[E0277]: the type `[isize]` cannot be indexed by `u8` --> FrequencyTableBytes.rs:24:14 | 24 | countTable[c] += 1; | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `u8` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<u8>` error[E0277]: the type `[isize]` cannot be indexed by `isize` --> FrequencyTableBytes.rs:32:18 | 32 | if countTable[x] > 0 { | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<isize>` error[E0277]: the type `[isize]` cannot be indexed by `isize` --> FrequencyTableBytes.rs:33:41 | 33 | let freq:f64 = f64::from(countTable[x]) / f64::from(totalCount); | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<isize>` error[E0277]: the trait bound `f64: From<isize>` is not satisfied --> FrequencyTableBytes.rs:33:57 | 33 | let freq:f64 = f64::from(countTable[x]) / f64::from(totalCount); | --------- ^^^^^^^^^^ the trait `From<isize>` is not implemented for `f64` | | | required by a bound introduced by this call | = help: the following other types implement trait `From<T>`: <f64 as From<bool>> <f64 as From<f32>> <f64 as From<i16>> <f64 as From<i32>> <f64 as From<i8>> <f64 as From<u16>> <f64 as From<u32>> <f64 as From<u8>> error[E0277]: the type `[isize]` cannot be indexed by `isize` --> FrequencyTableBytes.rs:34:76 | 34 | println!("{}", format!("{0:d}\t{0:02x}\t{1:d}\t{2:.4f}", x, countTable[x], freq)); | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<isize>` error: aborting due to 12 previous errors Some errors have detailed explanations: E0277, E0425. For more information about an error, try `rustc --explain E0277`.

Solution