-
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.
Merge pull request #19 from radixdlt/factor_instances_provider_simpli…
…fied_by_sketch_in_pr_description
- Loading branch information
Showing
18 changed files
with
661 additions
and
815 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"cSpell.words": [ | ||
"analyser", | ||
"Appendable", | ||
"Banksy", | ||
"bdfs", | ||
"Fulfillable", | ||
|
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
54 changes: 0 additions & 54 deletions
54
src/factor_instances_provider/agnostic_paths/quantities.rs
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 |
---|---|---|
@@ -1,57 +1,3 @@ | ||
use crate::prelude::*; | ||
|
||
pub const CACHE_FILLING_QUANTITY: usize = 30; | ||
|
||
#[derive(Clone, Debug, Hash, PartialEq, Eq)] | ||
pub enum QuantityToCacheToUseDirectly { | ||
OnlyCacheFilling { | ||
/// `CACHE_FILLING_QUANTITY` - `FOUND_IN_CACHE` | ||
fill_cache: usize, | ||
/// We peeked into the cache and found FactorInstance with the max index, which we must used | ||
/// when we calculate the next index path, we are gonna do `max(max_from_profile, max_from_cache)` | ||
/// where `max_from_cache` is this `max_index` field. | ||
instance_with_max_index: Option<HierarchicalDeterministicFactorInstance>, | ||
}, | ||
|
||
/// We will derive `remaining + extra_to_fill_cache` more instances | ||
/// | ||
/// If: | ||
/// CACHE_FILLING_QUANTITY: 30 | ||
/// FOUND_IN_CACHE: 12 | ||
/// REQUESTED: 14 | ||
/// | ||
/// Then `remaining` below will be `2` and `extra_to_fill_cache` will be | ||
/// `CACHE_FILLING_QUANTITY` (`30`) since all `FOUND_IN_CACHE` instances | ||
/// will be used and method `total_quantity_to_derive` below will return | ||
/// `2 + 30 = 32` | ||
ToCacheToUseDirectly { | ||
/// Remaining quantity to satisfy the request, `originally_requested - from_cache_instances.len()` | ||
/// Used later to split the newly derived instances into two groups, to cache and to use directly, | ||
/// can be zero. | ||
remaining: usize, | ||
|
||
/// Typically `CACHE_FILLING_QUANTITY` (always?) | ||
extra_to_fill_cache: usize, | ||
}, | ||
} | ||
|
||
impl QuantityToCacheToUseDirectly { | ||
pub fn max_index(&self) -> Option<HierarchicalDeterministicFactorInstance> { | ||
match self { | ||
Self::OnlyCacheFilling { | ||
fill_cache: _, | ||
instance_with_max_index, | ||
} => instance_with_max_index.clone(), | ||
Self::ToCacheToUseDirectly { .. } => None, | ||
} | ||
} | ||
pub fn total_quantity_to_derive(&self) -> usize { | ||
match self { | ||
Self::OnlyCacheFilling { fill_cache, .. } => *fill_cache, | ||
Self::ToCacheToUseDirectly { | ||
remaining, | ||
extra_to_fill_cache, | ||
} => *remaining + *extra_to_fill_cache, | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
mod next_derivation_entity_index_assigner; | ||
mod next_derivation_entity_index_cache_analyzing_assigner; | ||
mod next_derivation_entity_index_profile_analyzing_assigner; | ||
mod next_derivation_entity_index_with_ephemeral_offsets; | ||
mod next_derivation_entity_index_with_ephemeral_offsets_for_factor_source; | ||
mod offset_from_cache; | ||
|
||
pub use next_derivation_entity_index_assigner::*; | ||
pub use next_derivation_entity_index_cache_analyzing_assigner::*; | ||
pub use next_derivation_entity_index_profile_analyzing_assigner::*; | ||
pub use next_derivation_entity_index_with_ephemeral_offsets::*; | ||
pub use next_derivation_entity_index_with_ephemeral_offsets_for_factor_source::*; | ||
pub use offset_from_cache::*; |
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
22 changes: 22 additions & 0 deletions
22
...ces_provider/next_index_assigner/next_derivation_entity_index_cache_analyzing_assigner.rs
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,22 @@ | ||
use crate::prelude::*; | ||
|
||
pub struct NextDerivationEntityIndexCacheAnalyzingAssigner { | ||
cache: FactorInstancesCache, | ||
} | ||
impl NextDerivationEntityIndexCacheAnalyzingAssigner { | ||
pub fn new(cache: FactorInstancesCache) -> Self { | ||
Self { cache } | ||
} | ||
|
||
pub fn next( | ||
&self, | ||
factor_source_id: FactorSourceIDFromHash, | ||
index_agnostic_path: IndexAgnosticPath, | ||
) -> Result<Option<HDPathComponent>> { | ||
let max = self | ||
.cache | ||
.max_index_for(factor_source_id, index_agnostic_path); | ||
let Some(max) = max else { return Ok(None) }; | ||
max.add_one().map(Some) | ||
} | ||
} |
Oops, something went wrong.