From 7ce7e24b887c9bc58feed78de302c6ce3dae20ab Mon Sep 17 00:00:00 2001 From: uri singer Date: Thu, 15 Aug 2024 11:30:28 +0300 Subject: [PATCH 1/2] prefix searches now use an iterator --- README.md | 4 ++-- src/iter/prefix_iter.rs | 27 +++++++++++++++------------ src/map/trie.rs | 23 ++++++++++++++--------- src/trie/trie_impl.rs | 32 +++++++++++++++++++++++--------- 4 files changed, 54 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 00651c6..f091c22 100644 --- a/README.md +++ b/README.md @@ -64,8 +64,8 @@ assert_eq!( ); // common_prefix_search(): Find words which is included in `query`'s prefix. -let results_in_u8s: Vec> = trie.common_prefix_search("すしや").collect(); -let results_in_str: Vec = trie.common_prefix_search("すしや").collect(); +let results_in_u8s: Vec> = trie.common_prefix_search("すしや".bytes()).collect(); +let results_in_str: Vec = trie.common_prefix_search("すしや".bytes()).collect(); assert_eq!( results_in_str, vec![ diff --git a/src/iter/prefix_iter.rs b/src/iter/prefix_iter.rs index 1a0c897..db055ec 100644 --- a/src/iter/prefix_iter.rs +++ b/src/iter/prefix_iter.rs @@ -3,25 +3,28 @@ use crate::try_collect::{TryCollect, TryFromIterator}; use louds_rs::LoudsNodeNum; use std::marker::PhantomData; -#[derive(Debug, Clone)] +#[derive(Debug)] /// Iterates through all the common prefixes of a given query. -pub struct PrefixIter<'a, Label, Value, C, M> { +pub struct PrefixIter<'a, Label, I, Value, C, M> { trie: &'a Trie, - query: Vec