Skip to main content

reifydb_core/window/engine/
config.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 ReifyDB
3
4use crate::window::{engine::LatePolicy, span::Slot};
5
6pub const DEFAULT_STATE_CACHE_CAPACITY: usize = 1024;
7
8pub const DEFAULT_INTERNAL_STATE_CACHE_CAPACITY: usize = 1024;
9
10#[derive(Clone, Copy, Debug)]
11pub struct WindowEngineConfig {
12	late_policy: LatePolicy,
13	state_cache_capacity: usize,
14	internal_state_cache_capacity: usize,
15}
16
17impl WindowEngineConfig {
18	pub fn builder() -> WindowEngineConfigBuilder {
19		WindowEngineConfigBuilder::default()
20	}
21
22	pub fn late_policy(&self) -> LatePolicy {
23		self.late_policy
24	}
25
26	pub fn state_cache_capacity(&self) -> usize {
27		self.state_cache_capacity
28	}
29
30	pub fn internal_state_cache_capacity(&self) -> usize {
31		self.internal_state_cache_capacity
32	}
33}
34
35#[derive(Clone, Copy, Debug)]
36pub struct WindowEngineConfigBuilder {
37	late_policy: LatePolicy,
38	state_cache_capacity: usize,
39	internal_state_cache_capacity: usize,
40}
41
42impl Default for WindowEngineConfigBuilder {
43	fn default() -> Self {
44		Self {
45			late_policy: LatePolicy::Drop,
46			state_cache_capacity: DEFAULT_STATE_CACHE_CAPACITY,
47			internal_state_cache_capacity: DEFAULT_INTERNAL_STATE_CACHE_CAPACITY,
48		}
49	}
50}
51
52impl WindowEngineConfigBuilder {
53	pub fn late_policy(mut self, late_policy: LatePolicy) -> Self {
54		self.late_policy = late_policy;
55		self
56	}
57
58	pub fn state_cache_capacity(mut self, capacity: usize) -> Self {
59		self.state_cache_capacity = capacity;
60		self
61	}
62
63	pub fn internal_state_cache_capacity(mut self, capacity: usize) -> Self {
64		self.internal_state_cache_capacity = capacity;
65		self
66	}
67
68	pub fn build(self) -> WindowEngineConfig {
69		WindowEngineConfig {
70			late_policy: self.late_policy,
71			state_cache_capacity: self.state_cache_capacity,
72			internal_state_cache_capacity: self.internal_state_cache_capacity,
73		}
74	}
75}
76
77#[derive(Clone, Copy, Debug)]
78pub struct TumblingCarryConfig<C: Slot> {
79	base: WindowEngineConfig,
80	retention: Option<C::Duration>,
81}
82
83impl<C: Slot> TumblingCarryConfig<C> {
84	pub fn builder() -> TumblingCarryConfigBuilder<C> {
85		TumblingCarryConfigBuilder::new()
86	}
87
88	pub fn base(&self) -> WindowEngineConfig {
89		self.base
90	}
91
92	pub fn retention(&self) -> Option<C::Duration> {
93		self.retention
94	}
95}
96
97pub struct TumblingCarryConfigBuilder<C: Slot> {
98	base: WindowEngineConfig,
99	retention: Option<C::Duration>,
100}
101
102impl<C: Slot> TumblingCarryConfigBuilder<C> {
103	fn new() -> Self {
104		Self {
105			base: WindowEngineConfig::builder().build(),
106			retention: None,
107		}
108	}
109
110	pub fn base(mut self, base: WindowEngineConfig) -> Self {
111		self.base = base;
112		self
113	}
114
115	pub fn retention(mut self, retention: Option<C::Duration>) -> Self {
116		self.retention = retention;
117		self
118	}
119
120	pub fn build(self) -> TumblingCarryConfig<C> {
121		TumblingCarryConfig {
122			base: self.base,
123			retention: self.retention,
124		}
125	}
126}