-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move dummy generation of tables into tsql lib
- Loading branch information
Showing
7 changed files
with
85 additions
and
50 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,44 @@ | ||
use std::collections::HashMap; | ||
|
||
use hmac_sha256::HMAC; | ||
|
||
use crate::types::{Field, Table, TableExtra}; | ||
|
||
pub trait GenerateDummy { | ||
fn generate_dummy(number: usize) -> Self; | ||
} | ||
|
||
pub(crate) fn hash_number(input: usize) -> [u8; 32] { | ||
let bytes = input.to_le_bytes(); | ||
let h = HMAC::new(bytes); | ||
|
||
h.finalize() | ||
} | ||
|
||
pub(crate) fn u8s_to_string(input: &[u8]) -> String { | ||
input.iter().map(|item| (item % 24 + 65) as char).collect() | ||
} | ||
|
||
pub(crate) fn hash_number_and_stringify(input: usize) -> String { | ||
u8s_to_string(&hash_number(input)) | ||
} | ||
|
||
pub fn generate_table(counter: usize, fields_per_table: usize) -> Table { | ||
let name = hash_number_and_stringify(counter); | ||
|
||
let mut fields = HashMap::new(); | ||
|
||
for i in 0..fields_per_table { | ||
let field = Field::generate_dummy(i.wrapping_add(counter.wrapping_mul(100))); | ||
|
||
fields.insert(field.name.clone(), field); | ||
} | ||
|
||
let first_field_for_pk = fields.keys().next().unwrap().clone(); | ||
|
||
Table::new( | ||
name, | ||
fields, | ||
TableExtra::new_with_pk(vec![first_field_for_pk]), | ||
) | ||
} |
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