From e4825fd15eae7f9d400ee46e51e1ca6c6fd4dbae Mon Sep 17 00:00:00 2001 From: fxpineau Date: Tue, 28 Mar 2023 17:18:47 +0200 Subject: [PATCH] Add to_hz_ranges in store --- src/storage/u64idx/common.rs | 11 +++++++++++ src/storage/u64idx/mod.rs | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/src/storage/u64idx/common.rs b/src/storage/u64idx/common.rs index a30af15..7435c26 100644 --- a/src/storage/u64idx/common.rs +++ b/src/storage/u64idx/common.rs @@ -225,6 +225,17 @@ impl InternalMoc { InternalMoc::TimeSpace(_) => Err(String::from("Get ranges not possible for Time-Space MOCs")), } } + + pub(crate) fn get_hz_ranges(&self) -> Result>, String> { + match self { + InternalMoc::Frequency(moc) => Ok( + moc.into_range_moc_iter() + .map(|Range { start, end }| Frequency::::hash2freq(start)..Frequency::::hash2freq(end)) + .collect() + ), + _ => Err(String::from("Get Hz ranges only available for F-MOCs")), + } + } pub(crate) fn to_ascii(&self, fold: Option, writer: W) -> Result<(), String> diff --git a/src/storage/u64idx/mod.rs b/src/storage/u64idx/mod.rs index 555314c..6d3493d 100644 --- a/src/storage/u64idx/mod.rs +++ b/src/storage/u64idx/mod.rs @@ -265,6 +265,10 @@ impl U64MocStore { pub fn to_ranges(&self, index: usize) -> Result>, String> { store::exec_on_one_readonly_moc(index, InternalMoc::get_ranges) } + + pub fn to_hz_ranges(&self, index: usize) -> Result>, String> { + store::exec_on_one_readonly_moc(index, InternalMoc::get_hz_ranges) + } /////////////////////// // LOAD EXISTING MOC //