Skip to main content

reifydb_core/key/operator/keyspace/
distinct.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 ReifyDB
3
4use crate::{
5	key::{
6		operator::{
7			state::{GroupId, KeyspaceId},
8			traits::Keyspace,
9		},
10		typed::{
11			BoundedKey, DenseKey, KeyLayout,
12			direction::{Desc, Direction, KeyField},
13			layout::{KeyColumn, KeyColumnType, KeyLayout, KeyValue, KeyValues},
14		},
15	},
16	metrics::heap::HeapSize,
17};
18
19#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
20pub struct DistinctEntryKey {
21	pub group: Desc<GroupId>,
22}
23
24#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
25pub struct DistinctLayoutKey {}
26
27#[derive(Clone, Copy, Debug, PartialEq, Eq)]
28pub struct DistinctEntry;
29
30impl Keyspace for DistinctEntry {
31	const ID: KeyspaceId = KeyspaceId::DISTINCT_ENTRY;
32	const NAME: &'static str = "DISTINCT_ENTRY";
33	const RANGE_CACHED: bool = true;
34
35	type GroupedKey = DistinctEntryKey;
36	type Suffix = ();
37
38	fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
39		(key.group.0, ())
40	}
41
42	fn join(group: GroupId, _suffix: Self::Suffix) -> Self::GroupedKey {
43		DistinctEntryKey {
44			group: Desc(group),
45		}
46	}
47}
48
49#[derive(Clone, Copy, Debug, PartialEq, Eq)]
50pub struct DistinctLayout;
51
52impl Keyspace for DistinctLayout {
53	const ID: KeyspaceId = KeyspaceId::DISTINCT_LAYOUT;
54	const NAME: &'static str = "DISTINCT_LAYOUT";
55	const RANGE_CACHED: bool = true;
56
57	type GroupedKey = DistinctLayoutKey;
58	type Suffix = DistinctLayoutKey;
59
60	fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
61		(GroupId::ROOT, *key)
62	}
63
64	fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
65		suffix
66	}
67}