-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move VariablySizedColumns to executor crate
- Loading branch information
1 parent
78eac24
commit a2a5968
Showing
18 changed files
with
93 additions
and
80 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
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
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,48 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use std::collections::BTreeMap; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct VariablySizedColumn<F> { | ||
column_by_size: BTreeMap<usize, Vec<F>>, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct HasMultipleSizesError; | ||
|
||
impl<F> VariablySizedColumn<F> { | ||
/// Create a view where each column has a single size. Fails if any column has multiple sizes. | ||
pub fn get_only_size(&self) -> Result<&Vec<F>, HasMultipleSizesError> { | ||
if self.column_by_size.len() != 1 { | ||
return Err(HasMultipleSizesError); | ||
} | ||
Ok(self.column_by_size.values().next().unwrap()) | ||
} | ||
} | ||
|
||
pub fn get_only_size<F>( | ||
column: &[(String, VariablySizedColumn<F>)], | ||
) -> Result<Vec<(String, &Vec<F>)>, HasMultipleSizesError> { | ||
column | ||
.iter() | ||
.map(|(name, column)| Ok((name.clone(), column.get_only_size()?))) | ||
.collect() | ||
} | ||
|
||
pub fn get_only_size_cloned<F: Clone>( | ||
column: &[(String, VariablySizedColumn<F>)], | ||
) -> Result<Vec<(String, Vec<F>)>, HasMultipleSizesError> { | ||
get_only_size(column).map(|column| { | ||
column | ||
.into_iter() | ||
.map(|(name, column)| (name, column.clone())) | ||
.collect() | ||
}) | ||
} | ||
|
||
impl<F> From<Vec<F>> for VariablySizedColumn<F> { | ||
fn from(column: Vec<F>) -> Self { | ||
VariablySizedColumn { | ||
column_by_size: [(column.len(), column)].into_iter().collect(), | ||
} | ||
} | ||
} |
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
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