Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sriram98v committed Oct 12, 2023
2 parents 693b115 + 03a7c3e commit 5edc914
Show file tree
Hide file tree
Showing 2 changed files with 246 additions and 153 deletions.
52 changes: 3 additions & 49 deletions src/suffix_node.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{HashMap, HashSet};
use std::collections::HashMap;
use std::fmt::{Display, Debug};
use std::hash::Hash;
use std::option::Option;
Expand All @@ -7,9 +7,6 @@ use serde::{Serialize, Deserialize};
pub trait SuffixNode<T> {
fn set_parent(&mut self, parent: usize);
fn get_parent(&self)->Option<&usize>;
fn set_suffix_link(&mut self, link_node:usize);
fn get_suffix_link(&self)->Option<&usize>;
fn add_seq(&mut self, seq_id:&usize, start:&usize);
fn get_child(&self, child:&T)->Option<&usize>;
fn get_child_mut(&mut self, child:&T)->Option<&mut usize>;
fn set_child(&mut self, edge:T, child:usize);
Expand All @@ -22,8 +19,6 @@ pub trait SuffixNode<T> {
fn set_start(&mut self, new_start:usize);
fn has_children(&self)->bool;
fn get_children(&self)->&HashMap<T, usize>;
fn get_data(&self)->&HashMap<usize, HashSet<usize>>;
fn add_data(&mut self, new_data: HashMap<usize, HashSet<usize>>);
}


Expand All @@ -33,9 +28,7 @@ where
T: Display + Debug + Eq + PartialEq + Hash + Clone,
{
children: HashMap<T, usize>,
suffix_link: Option<usize>,
string_id: Option<usize>,
data: HashMap<usize, HashSet<usize>>,
parent: Option<usize>,
edge_length: usize,
start: usize,
Expand All @@ -46,17 +39,13 @@ where
T: Display + Debug + Eq + PartialEq + Hash + Clone,
{
pub fn new(children: HashMap<T, usize>,
suffix_link: Option<usize>,
string_id: Option<usize>,
data: HashMap<usize, HashSet<usize>>,
parent: Option<usize>,
edge_length: usize,
start: usize)->Node<T>{
Node {
start: usize)->Self{
Self {
children: children,
suffix_link: suffix_link,
string_id: string_id,
data: data,
parent: parent,
edge_length: edge_length,
start: start,
Expand All @@ -77,25 +66,6 @@ where
self.parent.as_ref()
}

fn set_suffix_link(&mut self, link_node:usize){
self.suffix_link = Some(link_node);
}

fn get_suffix_link(&self)->Option<&usize>{
self.suffix_link.as_ref()
}

fn add_seq(&mut self, seq_id:&usize, start:&usize){
match self.data.get_mut(seq_id){
None => {self.data.insert(seq_id.clone(), HashSet::from([start.clone()]));},
Some(i) => {
match i.contains(start){
false => {i.insert(start.clone());},
true => {},
};
}
};
}

fn get_child(&self, child:&T)->Option<&usize>{
self.children.get(child)
Expand Down Expand Up @@ -146,20 +116,4 @@ where
&self.children
}

fn get_data(&self)->&HashMap<usize, HashSet<usize>>{
&self.data
}

fn add_data(&mut self, new_data: HashMap<usize, HashSet<usize>>){
for (key, v) in new_data.iter(){
match self.data.get_mut(key){
None => {self.data.insert(key.clone(), v.clone());},
Some(values) => {
for value in v.iter(){
values.insert(value.clone());
}
},
};
}
}
}
Loading

0 comments on commit 5edc914

Please sign in to comment.