<commit_before>use std::boxed::Box;

#[derive(Debug)]
struct SearchTree<T> {
    left: Option<Box<SearchTree<T>>>,
    right: Option<Box<SearchTree<T>>>,
    key: T,
}

impl<T> SearchTree<T> where T: std::fmt::Debug + std::cmp::Eq + std::cmp::PartialOrd {
    fn inorder_tree(self) {
        self.left.map(|x| x.inorder_tree());
        println!("self.key = {:#?}", self.key);
        self.right.map(|x| x.inorder_tree());
    }

    fn search_tree(self, key: T ) -> Option<SearchTree<T>> {
        if self.key == key {
            return Some(self);
        }

        if key < self.key {
            match self.left {
                Some(tree) => tree.search_tree(key),
                None => None
            }
        } else {
            match self.right {
                Some(tree) => tree.search_tree(key),
                None => None
            }
        }
    }
}

fn main() {
    let left = SearchTree {
        left: None,
        right: None,
        key: 32,
    };

    let right = SearchTree {
        left: None,
        right: None,
        key: 43,
    };

    let root = SearchTree {
        left: Some(Box::new(left)),
        right: Some(Box::new(right)),
        key: 40,
    };

//    root.inorder_tree();

    let tree = root.search_tree(43);
    match tree {
        Some(t) => println!("t.key = {:#?}", t.key),
        None => println!(" None "),

    }

}<commit_msg>lifetime<commit_after>use std::boxed::Box;

#[derive(Debug)]
struct SearchTree<'a, T: 'a> {
    left: Option<Box<&'a SearchTree<'a,T>>>,
    right: Option<Box<&'a SearchTree<'a,T>>>,
    key: T,
}
fn do_nothing() {

}
impl<'a, T> SearchTree<'a, T> where T: std::fmt::Debug + std::cmp::Eq + std::cmp::PartialOrd {
    fn inorder_tree(&self) {
        match self.left {
            Some(ref tree) => tree.inorder_tree(),
            None => do_nothing(),
        }
        println!("self.key = {:#?}", self.key);
        match self.right {
            Some(ref tree) => tree.inorder_tree(),
            None => do_nothing(),
        }
    }

    fn search_tree(&'a self, key: T ) -> Option<&'a SearchTree<'a, T>> {
        if self.key == key {
            return Some(&self);
        }

        if key < self.key {
            match self.left {
                Some(ref tree) => tree.search_tree(key),
                None => None
            }
        } else {
            match self.right {
                Some(ref tree) => tree.search_tree(key),
                None => None
            }
        }
    }
}

fn main() {
    let left = SearchTree {
        left: None,
        right: None,
        key: 32,
    };

    let right = SearchTree {
        left: None,
        right: None,
        key: 43,
    };

    let root = SearchTree {
        left: Some(Box::new(&left)),
        right: Some(Box::new(&right)),
        key: 40,
    };

    root.inorder_tree();

    let tree = root.search_tree(43);
    match tree {
        Some(t) => println!("t.key = {:#?}", t.key),
        None => println!(" None "),

    }


    let x = create_box_value();
    println!("x = {:#?}", x);
    
}

fn create_box_value<'a>() -> Box<i32> {
    Box::new(32)
}
{'fraction_non_alphanumeric': 0.17106518282988872, 'fraction_numerical': 0.006359300476947536, 'mean_word_length': 1.705073086844368, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2036551', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1055, 'n_words': 218}