|
@@ -0,0 +1,27 @@
|
|
|
+use crate::node::Node;
|
|
|
+
|
|
|
+#[derive(Debug)]
|
|
|
+pub struct Set<T: Ord> {
|
|
|
+ root: Option<Box<Node<T>>>,
|
|
|
+}
|
|
|
+
|
|
|
+impl<T: Ord> Default for Set<T> {
|
|
|
+ fn default() -> Self {
|
|
|
+ Set { root: None }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl<T: Ord> Set<T> {
|
|
|
+ pub fn new() -> Self {
|
|
|
+ Default::default()
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn insert(&mut self, value: T) -> bool {
|
|
|
+ if let Some(ref mut node) = self.root {
|
|
|
+ node.insert(value)
|
|
|
+ } else {
|
|
|
+ self.root = Some(Box::new(Node::new(value)));
|
|
|
+ true
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|