#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
pub mod bits;
pub mod codec;
pub mod dataset;
mod error;
pub use codec::{decode, Codec};
pub use error::{Error, Result};
#[derive(Clone, Copy, Debug)]
pub struct Point {
pub timestamp: i64,
pub value: f64,
}
impl Point {
pub fn new(timestamp: i64, value: f64) -> Self {
Point { timestamp, value }
}
}
impl PartialEq for Point {
fn eq(&self, other: &Self) -> bool {
self.timestamp == other.timestamp && self.value.to_bits() == other.value.to_bits()
}
}
pub const RAW_POINT_BYTES: usize = 16;
pub fn chunk_by_window(points: &[Point], window_seconds: i64) -> alloc::vec::Vec<&[Point]> {
use alloc::vec::Vec;
if points.is_empty() {
return Vec::new();
}
if window_seconds <= 0 {
return alloc::vec![points];
}
let mut blocks = Vec::new();
let mut start = 0;
let mut current = points[0].timestamp.div_euclid(window_seconds);
for (index, point) in points.iter().enumerate() {
let window = point.timestamp.div_euclid(window_seconds);
if window != current {
blocks.push(&points[start..index]);
start = index;
current = window;
}
}
blocks.push(&points[start..]);
blocks
}