@@ -3,12 +3,16 @@ extern crate general_sam as general_sam_rs;
33use crate :: trie:: Trie ;
44use crate :: utils:: { char_or_byte_type, for_both, ByteSide , CharSide } ;
55
6- use general_sam_rs:: { sam as sam_rs, trie as trie_rs, trie_alike:: TravelEvent } ;
6+ use general_sam_rs:: {
7+ sam as sam_rs, trie as trie_rs, BTreeTransTable , BoxBisectTable , TransitionTable , TravelEvent ,
8+ } ;
79use pyo3:: { prelude:: * , types:: PyDict } ;
810use std:: { str:: from_utf8, sync:: Arc } ;
911
10- type RustGeneralSAM = char_or_byte_type ! ( sam_rs:: GeneralSAM ) ;
11- type RustGeneralSAMState < ' s > = char_or_byte_type ! ( sam_rs:: GeneralSAMState ; ' s) ;
12+ type RustBoxBisectGeneralSAM < T > = sam_rs:: GeneralSAM < BoxBisectTable < T > > ;
13+ type RustBoxBisectGeneralSAMState < ' s , T > = sam_rs:: GeneralSAMState < ' s , BoxBisectTable < T > > ;
14+ type RustGeneralSAM = char_or_byte_type ! ( RustBoxBisectGeneralSAM ) ;
15+ type RustGeneralSAMState < ' s > = char_or_byte_type ! ( RustBoxBisectGeneralSAMState ; ' s) ;
1216
1317#[ pyclass]
1418pub struct GeneralSAM ( pub Arc < RustGeneralSAM > ) ;
@@ -56,7 +60,7 @@ impl GeneralSAMState {
5660 for_both ! ( self . get_state( ) . as_ref( ) , state => {
5761 Python :: with_gil( |py| {
5862 if let Some ( node) = state. get_node( ) {
59- node. get_trans( ) . clone ( ) . into_py( py)
63+ BTreeTransTable :: from_kv_iter ( node. get_trans( ) . iter ( ) ) . into_py( py)
6064 } else {
6165 PyDict :: new( py) . into_py( py)
6266 }
@@ -215,27 +219,30 @@ impl GeneralSAMState {
215219#[ pymethods]
216220impl GeneralSAM {
217221 #[ staticmethod]
218- pub fn construct_from_chars ( s : & str ) -> Self {
222+ pub fn from_chars ( s : & str ) -> Self {
219223 GeneralSAM ( Arc :: new ( CharSide (
220- sam_rs:: GeneralSAM :: construct_from_chars ( s. chars ( ) ) ,
224+ sam_rs:: GeneralSAM :: < BTreeTransTable < _ > > :: from_chars ( s. chars ( ) )
225+ . alter_trans_table_into ( ) ,
221226 ) ) )
222227 }
223228
224229 #[ staticmethod]
225- pub fn construct_from_bytes ( s : & [ u8 ] ) -> Self {
230+ pub fn from_bytes ( s : & [ u8 ] ) -> Self {
226231 GeneralSAM ( Arc :: new ( ByteSide (
227- sam_rs:: GeneralSAM :: construct_from_bytes ( s ) ,
232+ sam_rs:: GeneralSAM :: < BTreeTransTable < _ > > :: from_bytes ( s ) . alter_trans_table_into ( ) ,
228233 ) ) )
229234 }
230235
231236 #[ staticmethod]
232- pub fn construct_from_trie ( trie : & Trie ) -> Self {
237+ pub fn from_trie ( trie : & Trie ) -> Self {
233238 match trie. 0 . as_ref ( ) {
234239 CharSide ( trie_chars) => GeneralSAM ( Arc :: new ( CharSide (
235- sam_rs:: GeneralSAM :: construct_from_trie ( trie_chars. get_root_state ( ) ) ,
240+ sam_rs:: GeneralSAM :: < BTreeTransTable < _ > > :: from_trie ( trie_chars. get_root_state ( ) )
241+ . alter_trans_table_into ( ) ,
236242 ) ) ) ,
237243 ByteSide ( trie_bytes) => GeneralSAM ( Arc :: new ( ByteSide (
238- sam_rs:: GeneralSAM :: construct_from_trie ( trie_bytes. get_root_state ( ) ) ,
244+ sam_rs:: GeneralSAM :: < BTreeTransTable < _ > > :: from_trie ( trie_bytes. get_root_state ( ) )
245+ . alter_trans_table_into ( ) ,
239246 ) ) ) ,
240247 }
241248 }
0 commit comments