Skip to content

Commit

Permalink
feature: Use new louds-rs function.
Browse files Browse the repository at this point in the history
  • Loading branch information
shanecelis committed Apr 30, 2024
1 parent 693ea94 commit 9754bab
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ categories = ["compression", "data-structures"]
edition = "2021"

[dependencies]
louds-rs = "0.6"
louds-rs = "0.7"
mem_dbg = { version = "0.1.4", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }

Expand Down
42 changes: 21 additions & 21 deletions src/inc_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
//! the loop.
use crate::{
map::Trie,
// try_collect::{TryCollect, TryFromIterator},
try_collect::{TryCollect, TryFromIterator},
};
use louds_rs::LoudsNodeNum;

Expand Down Expand Up @@ -184,34 +184,34 @@ impl<'a, Label: Ord, Value> IncSearch<'a, Label, Value> {
self.trie.value(self.node)
}

// Return the current prefix for this search.
// pub fn prefix<C, M>(&self) -> C
// where
// C: TryFromIterator<Label, M>,
// Label: Clone,
// {
// let mut v: Vec<Label> = self.trie.child_to_ancestors(self.node)
// .map(|node| self.trie.label(node).clone()).collect();
// v.reverse();
// v.into_iter().try_collect().expect("Could not collect")
// }
/// Return the current prefix for this search.
pub fn prefix<C, M>(&self) -> C
where
C: TryFromIterator<Label, M>,
Label: Clone,
{
let mut v: Vec<Label> = self.trie.child_to_ancestors(self.node)
.map(|node| self.trie.label(node).clone()).collect();
v.reverse();
v.into_iter().try_collect().expect("Could not collect")
}

/// Returne the length of the current prefix for this search.
pub fn prefix_len(&self) -> usize {
// TODO: If PR for child_to_ancestors is accepted. Use the iterator and
// remove `pub(crate)` from Trie.louds field. Also uncomment prefix()
// above.

// self.trie.child_to_ancestors(self.node).count()
self.trie.child_to_ancestors(self.node).count()

let mut node = self.node;
let mut count = 0;
while node.0 > 1 {
let index = self.trie.louds.node_num_to_index(node);
node = self.trie.louds.child_to_parent(index);
count += 1;
}
count
// let mut node = self.node;
// let mut count = 0;
// while node.0 > 1 {
// let index = self.trie.louds.node_num_to_index(node);
// node = self.trie.louds.child_to_parent(index);
// count += 1;
// }
// count
}

// This isn't actually possible.
Expand Down
2 changes: 1 addition & 1 deletion src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use mem_dbg::MemDbg;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// A trie for sequences of the type `Label`; each sequence has an associated `Value`.
pub struct Trie<Label, Value> {
pub(crate) louds: Louds,
louds: Louds,

/// (LoudsNodeNum - 2) -> TrieLabel
trie_labels: Vec<TrieLabel<Label, Value>>,
Expand Down
8 changes: 4 additions & 4 deletions src/map/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::Trie;
use crate::inc_search::IncSearch;
use crate::iter::{PostfixIter, PrefixIter, SearchIter};
use crate::try_collect::{TryCollect, TryFromIterator};
use louds_rs::{ChildNodeIter, LoudsNodeNum};
use louds_rs::{ChildNodeIter, LoudsNodeNum, AncestorNodeIter};
use std::iter::FromIterator;

impl<Label: Ord, Value> Trie<Label, Value> {
Expand Down Expand Up @@ -211,9 +211,9 @@ impl<Label: Ord, Value> Trie<Label, Value> {
self.trie_labels[(node_num.0 - 2) as usize].value.as_mut()
}

// pub (crate) fn child_to_ancestors(&self, node_num: LoudsNodeNum) -> AncestorNodeIter {
// self.louds.child_to_ancestors(node_num)
// }
pub (crate) fn child_to_ancestors(&self, node_num: LoudsNodeNum) -> AncestorNodeIter {
self.louds.child_to_ancestors(node_num)
}
}

impl<Label, Value, C> FromIterator<(C, Value)> for Trie<Label, Value>
Expand Down

0 comments on commit 9754bab

Please sign in to comment.