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