From be6924fe4c8b05218fb0c4d0e1d578d930c983e4 Mon Sep 17 00:00:00 2001 From: timofey <tim@ongoteam.yaconnect.com> Date: Sun, 18 Jun 2023 12:28:58 +0000 Subject: [PATCH] `rstd::colections::tree` --- src/rstd/collections.rs | 1 + src/rstd/collections/tree.rs | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/rstd/collections/tree.rs diff --git a/src/rstd/collections.rs b/src/rstd/collections.rs index 3db9aad..926addf 100644 --- a/src/rstd/collections.rs +++ b/src/rstd/collections.rs @@ -3,3 +3,4 @@ pub mod avl; pub mod pair; pub mod stack; +pub mod tree; diff --git a/src/rstd/collections/tree.rs b/src/rstd/collections/tree.rs new file mode 100644 index 0000000..10ff42d --- /dev/null +++ b/src/rstd/collections/tree.rs @@ -0,0 +1,40 @@ +use std::{error::Error, fmt::Display}; + +use crate::rstd::{atomic::au64::*, point::*}; + +#[derive(Debug)] +pub enum TreeParseError<E> { + Int(IntParseError), + Point(PointParseError), + Key(E), +} + +impl<E> From<IntParseError> for TreeParseError<E> { + fn from(value: IntParseError) -> Self { + Self::Int(value) + } +} + +impl<E> From<PointParseError> for TreeParseError<E> { + fn from(value: PointParseError) -> Self { + Self::Point(value) + } +} + +impl<E: Display> Display for TreeParseError<E> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Int(int_error) => { + write!(f, "failed to parse AVL tree height: {int_error}") + } + Self::Point(point_error) => { + write!(f, "failed to parse AVL node reference: {point_error}") + } + Self::Key(key_error) => { + write!(f, "failed to parse AVL node key: {key_error}") + } + } + } +} + +impl<E: Error> Error for TreeParseError<E> {}