four hundred and something megabytes of Pure Inefficiency
This commit is contained in:
1 parent
bcea06ddc2
commit
98fafe89fc
3 files changed
+82
-3
No files matched your search
+1
-1
Submodule lda_ansi updated: f59285d3c9...4bb27986a0.
@@ -1,12 +1,15 @@
|
|||||||
// #![allow(unused)] // SHUT UP
|
// #![allow(unused)] // SHUT UP
|
||||||
|
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
use lda_ansi::{ansi_backbone::Style as StyleConstruct, ansi_styles::Style};
|
use lda_ansi::{ansi_backbone::Style as StyleConstruct, ansi_styles::Style};
|
||||||
use lda_sd_visualizer::{
|
use lda_sd_visualizer::{
|
||||||
compare_format, formatter::formatted_comparison, formatter2::compare2_format,
|
compare_format, formatter::formatted_comparison, formatter2::compare2_format,
|
||||||
};
|
};
|
||||||
use lda_strdist::{levenstein_distance, wrapper_::EditOperationVec, EditCost};
|
use lda_strdist::{levenstein_distance, wrapper_::EditOperationVec, EditCost};
|
||||||
|
|
||||||
fn main() {
|
#[allow(dead_code)]
|
||||||
|
fn it_works() {
|
||||||
let inp1 = "this is similar";
|
let inp1 = "this is similar";
|
||||||
let inp2 = "is this important";
|
let inp2 = "is this important";
|
||||||
let (_, uuh) = levenstein_distance(inp1, inp2, &EditCost::default());
|
let (_, uuh) = levenstein_distance(inp1, inp2, &EditCost::default());
|
||||||
@@ -40,3 +43,79 @@ fn main() {
|
|||||||
|
|
||||||
// NO IT DOESNT
|
// NO IT DOESNT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, BufReader, Read};
|
||||||
|
|
||||||
|
fn read_file_in_chunks(path: &Path, chunk_size: usize) -> io::Result<Vec<u8>> {
|
||||||
|
let file = File::open(path)?;
|
||||||
|
let mut reader = BufReader::new(file);
|
||||||
|
let mut buffer = Vec::new();
|
||||||
|
let mut chunk = vec![0; chunk_size];
|
||||||
|
|
||||||
|
while let Ok(bytes_read) = reader.read(&mut chunk) {
|
||||||
|
if bytes_read == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buffer.extend_from_slice(&chunk[..bytes_read]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(buffer)
|
||||||
|
}
|
||||||
|
fn compare_binary_data(data1: &[u8], data2: &[u8]) -> (String, String) {
|
||||||
|
let hex1 = data1
|
||||||
|
.iter()
|
||||||
|
.map(|w| format!("{:02x}", w))
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join(" ");
|
||||||
|
let hex2 = data2
|
||||||
|
.iter()
|
||||||
|
.map(|w| format!("{:02x}", w))
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join(" ");
|
||||||
|
|
||||||
|
let (str1, str2) = formatted_comparison(&hex1, &hex2);
|
||||||
|
(str1, str2)
|
||||||
|
}
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let path = Path::new(r"C:\Users\Admin\Documents\iwmproj");
|
||||||
|
println!("{:#?}", std::env::current_dir()?.display());
|
||||||
|
std::env::set_current_dir(path)?;
|
||||||
|
println!("{:#?}", std::env::current_dir()?.display());
|
||||||
|
|
||||||
|
let c = read_file_in_chunks(Path::new("New-note.iwm"), 1024)?;
|
||||||
|
let d = read_file_in_chunks(Path::new("One-note.iwm"), 1024)?;
|
||||||
|
|
||||||
|
{
|
||||||
|
let (str1, str2) = compare_binary_data(&c, &d);
|
||||||
|
println!(
|
||||||
|
"Hex Representation:\nfrom:\n{str1}{0}\nto:\n{str2}{0}\n\n",
|
||||||
|
StyleConstruct::new().style(Style::Reset)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let str_c: String = c.iter().map(|&w| char::from(w)).collect();
|
||||||
|
let str_d: String = d.iter().map(|&w| char::from(w)).collect();
|
||||||
|
|
||||||
|
let (str1, str2) = formatted_comparison(&str_c, &str_d);
|
||||||
|
println!(
|
||||||
|
"Pure String:\nfrom:\n{str1}{0}\nto:\n{str2}{0}\n\n",
|
||||||
|
StyleConstruct::new().style(Style::Reset)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let deb_c: String = format!("{:#?}",c.iter().map(|&w| char::from(w)).collect::<String>());
|
||||||
|
let deb_d: String = format!("{:#?}",d.iter().map(|&w| char::from(w)).collect::<String>());
|
||||||
|
|
||||||
|
let (str1, str2) = formatted_comparison(&deb_c, &deb_d);
|
||||||
|
println!(
|
||||||
|
"Formatted String:\nfrom:\n{str1}{0}\nto:\n{str2}{0}\n\n",
|
||||||
|
StyleConstruct::new().style(Style::Reset)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
+1
-1
Submodule lda_strdist updated: 827f1e4b75...ddd3b7bbb9.
Reference in new issue
Block a user