Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: derive Clone and Debug for some structures #39

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/sam/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub type GeneralSAMNodeID = usize;
pub const SAM_NIL_NODE_ID: GeneralSAMNodeID = 0;
pub const SAM_ROOT_NODE_ID: GeneralSAMNodeID = 1;

#[derive(Debug, Clone)]
#[derive(Clone, Debug)]
pub struct GeneralSAMNode<TransTable: TransitionTable> {
trans: TransTable,
accept: bool,
Expand All @@ -22,7 +22,7 @@ pub struct GeneralSAMNode<TransTable: TransitionTable> {
}

/// A general suffix automaton.
#[derive(Debug, Clone)]
#[derive(Clone, Debug)]
pub struct GeneralSAM<TransTable: TransitionTable> {
node_pool: Vec<GeneralSAMNode<TransTable>>,
topo_and_suf_len_sorted_order: Vec<GeneralSAMNodeID>,
Expand Down
7 changes: 6 additions & 1 deletion src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{

use crate::GeneralSAMNodeID;

#[derive(Clone, Debug)]
pub struct WithKeyDerefedIter<
'a,
KeyType: 'a + Clone,
Expand All @@ -26,6 +27,7 @@ impl<'a, KeyType: 'a + Clone, IterType: Iterator<Item = (&'a KeyType, &'a Genera
}
}

#[derive(Clone, Debug)]
pub struct TransitionIter<
'a,
KeyType: 'a,
Expand Down Expand Up @@ -180,6 +182,7 @@ fn bisect_unstable<K: Ord, V, C: AsRef<[(K, V)]>>(container: C, key: &K) -> Opti
}
}

#[derive(Clone, Debug)]
pub struct BisectTable<
K: Clone + Ord,
C: AsRef<[(K, GeneralSAMNodeID)]>
Expand All @@ -190,6 +193,7 @@ pub struct BisectTable<
phantom: PhantomData<K>,
}

#[derive(Clone, Debug)]
pub struct BisectTableIter<'s, K: Clone + Ord> {
inner: core::slice::Iter<'s, (K, GeneralSAMNodeID)>,
}
Expand Down Expand Up @@ -265,7 +269,7 @@ impl SmallAlphabet for u8 {
}
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct WholeAlphabetTable<
K: SmallAlphabet,
C: AsRef<[Option<GeneralSAMNodeID>]>
Expand All @@ -277,6 +281,7 @@ pub struct WholeAlphabetTable<
phantom: PhantomData<K>,
}

#[derive(Clone, Debug)]
pub struct WholeAlphabetTableIter<'s, K: SmallAlphabet> {
inner: std::iter::Enumerate<core::slice::Iter<'s, Option<GeneralSAMNodeID>>>,
phantom: PhantomData<K>,
Expand Down
8 changes: 4 additions & 4 deletions src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ pub type TrieNodeID = GeneralSAMNodeID;
pub const TRIE_NIL_NODE_ID: TrieNodeID = 0;
pub const TRIE_ROOT_NODE_ID: TrieNodeID = 1;

#[derive(Debug, Clone)]
#[derive(Clone, Debug)]
pub struct TrieNode<TransTable: TransitionTable> {
trans: TransTable,
parent: TrieNodeID,
pub accept: bool,
}

#[derive(Debug, Clone)]
#[derive(Clone, Debug)]
pub struct Trie<TransTable: TransitionTable> {
node_pool: Vec<TrieNode<TransTable>>,
}

#[derive(Debug, Clone)]
#[derive(Clone, Debug)]
pub struct TrieState<'s, TransTable: TransitionTable> {
pub trie: &'s Trie<TransTable>,
pub node_id: TrieNodeID,
Expand Down Expand Up @@ -172,7 +172,7 @@ impl<'s, TransTable: TransitionTable> TrieState<'s, TransTable> {
}
}

#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct NextTrieStateIter<'s, TransTable: TransitionTable> {
state: TrieState<'s, TransTable>,
iter: TransTable::IterType<'s>,
Expand Down
7 changes: 4 additions & 3 deletions src/trie_alike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,14 @@ pub trait TrieNodeAlike {
/// This struct implements `TrieNodeAlike` for any iterator.
///
/// It can be used to construct a suffix automaton directly from a sequence.
#[derive(Clone, Debug)]
pub struct IterAsChain<Iter: Iterator> {
iter: Iter,
val: Option<Iter::Item>,
pub iter: Iter,
pub val: Option<Iter::Item>,
}

pub struct IterAsChainNextStateIter<Iter: Iterator> {
state: Option<IterAsChain<Iter>>,
pub state: Option<IterAsChain<Iter>>,
}

impl<Iter: Iterator> From<Iter> for IterAsChain<Iter> {
Expand Down
1 change: 1 addition & 0 deletions src/utils/tokenize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use super::suffixwise::SuffixInTrieData;
/// the longest word matching the prefix of the suffix is stored in the rope.
/// And the information stored in a state
/// will be further merged in the ropes of its successors.
#[derive(Clone, Debug)]
pub struct GreedyTokenizer<
's,
TransTable: TransitionTable,
Expand Down