Skip to main content

antecedent_data/
temporal.rs

1//! Temporal sampling metadata (series length / regularity).
2//!
3//! Node keys and dense unfolding indexes live in `antecedent-core`.
4//!
5//! SPDX-License-Identifier: MIT OR Apache-2.0
6
7pub use antecedent_core::{TemporalIndexError, TemporalIndexer, TemporalNodeKey};
8
9/// Sampling regularity metadata (not used as lag duration for irregular data).
10#[derive(Clone, Debug, Eq, PartialEq)]
11pub enum SamplingRegularity {
12    /// Regular sampling with interval nanoseconds.
13    Regular {
14        /// Interval between samples in nanoseconds.
15        interval_ns: u64,
16    },
17    /// Irregular sampling.
18    Irregular,
19}
20
21/// Time index metadata for series data.
22#[derive(Clone, Debug, Eq, PartialEq)]
23pub struct TimeIndex {
24    /// Regularity.
25    pub regularity: SamplingRegularity,
26    /// Number of time points.
27    pub length: usize,
28}
29
30#[cfg(test)]
31mod tests {
32    use antecedent_core::VariableId;
33
34    use super::*;
35
36    #[test]
37    fn reexport_indexer_round_trip() {
38        let idx = TemporalIndexer::new(3, 2, 4).unwrap();
39        let key = TemporalNodeKey { variable: VariableId::from_raw(1), offset: -1 };
40        let dense = idx.dense_id(key).unwrap();
41        assert_eq!(idx.key_of(dense).unwrap(), key);
42    }
43}