// use crate::util::trie::GetEdgeResult::{EdgeKeyIsPrefix, EqualKeys, KeyIsPrefix}; // use std::collections::HashMap; // use std::rc::Rc; // // pub struct RadixTrie { // root: RadixTrieNode, // } // // struct RadixTrieNode { // edges: HashMap>, // value: Option>, // } // // impl RadixTrie { // pub fn new() -> Self { // RadixTrie { // root: Default::default(), // } // } // // pub fn insert(&mut self, key: &str, value: &Rc) { // self.root.insert_helper(key, value); // } // // pub fn remove(&mut self, key: &str) { // todo!() // } // // pub fn find(&self, key: &str) -> Option> { // todo!() // } // } // // impl Default for RadixTrieNode { // fn default() -> Self { // RadixTrieNode::new() // } // } // // enum GetEdgeResult<'a, T> { // EqualKeys, // KeyIsPrefix(&'a str, &'a mut RadixTrieNode), // common prefix and target node // EdgeKeyIsPrefix(&'a str, &'a mut RadixTrieNode), // non-common suffix and target node, // None, // } // // impl RadixTrieNode { // fn new() -> Self { // RadixTrieNode { // edges: HashMap::new(), // value: None, // } // } // // fn get_edge<'a>(&'a mut self, key: &'a str) -> GetEdgeResult<'a, T> { // for (edge_key, edge_node) in self.edges.iter_mut() { // // Case: edge_key == key: overwrite data // if *key == *edge_key { // return EqualKeys; // } // // // Find how many common characters there are starting from the beginning and terminating // // as soon as there is no match // let mut i = 0; // 'number_of_common_chars: for (key_char, edge_key_char) in // key.chars().zip(edge_key.chars()) // { // if key_char == edge_key_char { // i += 1; // } else { // break 'number_of_common_chars; // } // } // // // Case: key's first char does not match at all: continue searching // if i == 0 { // continue; // } // // // Case: key is prefix of edge_key // if i < edge_key.len() { // return KeyIsPrefix(key, edge_node); // } // // if i == edge_key.len() { // panic!( // "Should not have gotten here: counted common chars equals edge_key's length." // ) // } // // return EdgeKeyIsPrefix(&edge_key[i..], edge_node); // } // GetEdgeResult::None // } // // fn insert_helper(&mut self, key: &str, value: &Rc) { // match self.get_edge(key) { // EqualKeys => { // let edge_node = self.edges.get_mut(key).unwrap(); // edge_node.value = Some(value.clone()); // } // KeyIsPrefix(prefix, edge_node) => { // // split like asparagus break // let old_target_node = self.edges.remove(key).unwrap(); // // // let mut common_prefix_node: RadixTrieNode = RadixTrieNode::new(); // } // EdgeKeyIsPrefix(suffix, edge_node) => { // // recursive on edge_node // edge_node.insert_helper(suffix, value); // } // GetEdgeResult::None => { // let mut new_edge_node = RadixTrieNode::new(); // new_edge_node.value = Some(value.clone()); // self.edges.insert(String::from(key), new_edge_node); // } // } // } // }