1use std::{cmp::Ordering, sync::Arc};
4
5use crate::{EntityId, KwId};
6
7#[derive(Clone, Copy, Debug)]
9pub struct TotalF64(pub f64);
10
11impl TotalF64 {
12 #[must_use]
14 pub const fn sortable_bits(self) -> u64 {
15 let bits = self.0.to_bits();
16 if (bits & (1_u64 << 63)) == 0 {
17 bits ^ (1_u64 << 63)
18 } else {
19 !bits
20 }
21 }
22}
23impl PartialEq for TotalF64 {
24 fn eq(&self, other: &Self) -> bool {
25 self.sortable_bits() == other.sortable_bits()
26 }
27}
28impl Eq for TotalF64 {}
29impl PartialOrd for TotalF64 {
30 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
31 Some(self.cmp(other))
32 }
33}
34impl Ord for TotalF64 {
35 fn cmp(&self, other: &Self) -> Ordering {
36 self.sortable_bits().cmp(&other.sortable_bits())
37 }
38}
39
40#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
42pub enum Value {
43 Bool(bool),
45 Long(i64),
47 Double(TotalF64),
49 Instant(i64),
51 Uuid(u128),
53 Keyword(KwId),
55 Str(Arc<str>),
57 Bytes(Arc<[u8]>),
59 Ref(EntityId),
61}
62
63impl Value {
64 #[must_use]
66 pub const fn has_type(&self, value_type: crate::ValueType) -> bool {
67 matches!(
68 (self, value_type),
69 (Self::Bool(_), crate::ValueType::Bool)
70 | (Self::Long(_), crate::ValueType::Long)
71 | (Self::Double(_), crate::ValueType::Double)
72 | (Self::Instant(_), crate::ValueType::Instant)
73 | (Self::Uuid(_), crate::ValueType::Uuid)
74 | (Self::Keyword(_), crate::ValueType::Keyword)
75 | (Self::Str(_), crate::ValueType::Str)
76 | (Self::Bytes(_), crate::ValueType::Bytes)
77 | (Self::Ref(_), crate::ValueType::Ref)
78 )
79 }
80}