use std::{cmp::Ordering, sync::Arc};
use crate::{EntityId, KwId};
#[derive(Clone, Copy, Debug)]
pub struct TotalF64(pub f64);
impl TotalF64 {
#[must_use]
pub const fn sortable_bits(self) -> u64 {
let bits = self.0.to_bits();
if (bits & (1_u64 << 63)) == 0 {
bits ^ (1_u64 << 63)
} else {
!bits
}
}
}
impl PartialEq for TotalF64 {
fn eq(&self, other: &Self) -> bool {
self.sortable_bits() == other.sortable_bits()
}
}
impl Eq for TotalF64 {}
impl PartialOrd for TotalF64 {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for TotalF64 {
fn cmp(&self, other: &Self) -> Ordering {
self.sortable_bits().cmp(&other.sortable_bits())
}
}
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub enum Value {
Bool(bool),
Long(i64),
Double(TotalF64),
Instant(i64),
Uuid(u128),
Keyword(KwId),
Str(Arc<str>),
Bytes(Arc<[u8]>),
Ref(EntityId),
}
impl Value {
#[must_use]
pub const fn has_type(&self, value_type: crate::ValueType) -> bool {
matches!(
(self, value_type),
(Self::Bool(_), crate::ValueType::Bool)
| (Self::Long(_), crate::ValueType::Long)
| (Self::Double(_), crate::ValueType::Double)
| (Self::Instant(_), crate::ValueType::Instant)
| (Self::Uuid(_), crate::ValueType::Uuid)
| (Self::Keyword(_), crate::ValueType::Keyword)
| (Self::Str(_), crate::ValueType::Str)
| (Self::Bytes(_), crate::ValueType::Bytes)
| (Self::Ref(_), crate::ValueType::Ref)
)
}
}