extern crate core;
pub mod models;
pub mod io;
pub mod helpers;
pub mod csv;
pub mod extensions;
pub mod features;
pub mod decoders;
pub mod encoders;
pub mod parallel;
pub mod macros;
#[cfg(test)]
mod test {
use crate::csv::csv_reader::CsvReaderWithMap;
use crate::decoders::decoders::Encoding;
use crate::models::csv_config::CsvConfig;
use crate::models::shared::Shared;
use crate::parallel::parallel_reader::parallel_processing_csv;
use crate::parallel::row_parallel::RowParallel;
use crate::{get_bool, get_i32, get_str};
use std::collections::HashSet;
use std::sync::{Arc, Mutex};
#[test]
#[allow(dead_code, unused_assignments,unused_variables)]
fn read_csv_one_core(){
let cfg = CsvConfig::new(
b',',
0u8,
b'\n',
Encoding::Windows1252,
false
);
let mut f = match CsvReaderWithMap::open("data.csv", &cfg) {
Ok(f) => f,
Err(e) => panic!("{}", e)
};
let mut cities :HashSet<String>= HashSet::with_capacity(195);
while let Some(row) = f.next_raw() {
let city = row.get_index(6 );
let name = city.get_utf8_as_str();
let _ = get_bool!(row,1);
let num = city.get_i8();
let i = get_i32!(row,2);
let city = row.get_index(6 ).get_as_cow_decoded(Encoding::Windows1252);
let city = get_str!(row,6, Encoding::Windows1252);
if !cities.contains(name){
cities.insert(name.to_string());
}
}
assert_ne!(cities.len(), 0);
}
#[test]
#[allow(dead_code, unused_assignments,unused_variables)]
fn read_csv_multicore(){
let cfg = CsvConfig::new(
b',',
0u8,
b'\n',
Encoding::Windows1252,
false
);
let f = match CsvReaderWithMap::open("data.csv", &cfg) {
Ok(f) => f,
Err(e) => panic!("{}", e)
};
let data = f.get_slice();
let shared = Shared::<i32>::default();
let closure = |row: &mut RowParallel<'_>, id_thread:usize, target: Arc<Mutex<i32>>| {
let _ = id_thread;
let _actual = row.get_row();
let next = row.peek_next();
let mut lock = target.lock().unwrap();
*lock += 1;
};
parallel_processing_csv(
data,
b'\n',
b';',
b'"',
false,
closure,
shared.arc(),
);
println!("Iterated Lines: {:.2}", shared.lock())
}
}