-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed for NaN in exponential and improvements + bson
- Loading branch information
Showing
17 changed files
with
256 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ Cargo.lock | |
# ignore json in the root | ||
*.csv | ||
*.json | ||
*.bson | ||
*.bincode | ||
*.txt | ||
*.mermaid | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use bson::{SerializerOptions, Document}; | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Debug,Serialize,Deserialize)] | ||
struct Bison { | ||
name: String, | ||
age: u16, | ||
place: String, | ||
phone: u16, | ||
} | ||
|
||
|
||
pub fn check_bson() { | ||
let i = 5; | ||
let bison = Bison { | ||
name: format!("Name {}", i), | ||
age: i as u16, | ||
place: format!("Place {}", i), | ||
phone: i as u16, | ||
}; | ||
|
||
let options = SerializerOptions::builder().human_readable(false).build(); | ||
let bson = bson::to_bson_with_options(&bison, options).unwrap(); | ||
println!("{:?}", bson); | ||
|
||
// let mut doc = Document::new(); | ||
// doc.insert("array".to_string(), bson); | ||
|
||
// let mut buf = Vec::new(); | ||
// bson.to_writer(&mut buf).unwrap(); | ||
match bson::to_vec(&bison) { | ||
Ok(buf) => std::fs::write("data.bson", buf).expect("Failed to create file"), | ||
Err(err) => panic!("Failed to serialized bison.\n\tError: {err:?}") | ||
} | ||
} | ||
|
||
|
||
pub fn check_bson_vec() { | ||
let mut bisons: Vec<Bison> = Vec::with_capacity(1000); | ||
for i in 1..3 { | ||
bisons.push(Bison { | ||
name: format!("Name {}", i), | ||
age: i as u16, | ||
place: format!("Place {}", i), | ||
phone: i as u16, | ||
}); | ||
} | ||
|
||
let options = SerializerOptions::builder().human_readable(false).build(); | ||
let bson = bson::to_bson_with_options(&bisons, options).unwrap(); | ||
println!("{:?}", bson); | ||
|
||
let mut doc = Document::new(); | ||
doc.insert("array".to_string(), bson); | ||
|
||
let mut buf = Vec::new(); | ||
doc.to_writer(&mut buf).unwrap(); | ||
|
||
std::fs::write("data.bson", buf).expect("Failed to create file"); | ||
} | ||
|
||
|
||
pub fn main () { | ||
check_bson(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use bson; | ||
use super::super::StatsRec; | ||
use std::{fs, io}; | ||
use super::StatsRecJson; | ||
|
||
|
||
pub fn dump_file(file_name: &str, stats: StatsRec) { | ||
let srj: StatsRecJson = stats.into(); | ||
println!("input:\n{srj:#?}"); | ||
// let buf = bson::to_vec(&srj).unwrap(); | ||
// match fs::write(file_name, buf) { | ||
// Ok(()) => (), | ||
// Err(err) => panic!("failed to Serialize !!\n\tError={err:?}"), | ||
// } | ||
|
||
let options = bson::SerializerOptions::builder().human_readable(false).build(); | ||
let doc = bson::to_document_with_options(&srj, options).unwrap(); | ||
let f = fs::File::create(file_name).expect("Failed to open file"); | ||
let writer = io::BufWriter::new(f); | ||
match doc.to_writer(writer) { | ||
Ok(()) => (), | ||
Err(err) => panic!("failed to Serialize !!\n\tError={err:?}") | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.