@@ -160,3 +160,58 @@ pub fn compressed_3_3_from_0_to_13_with_state() -> BTreeMap<i64, StateGroupEntry
160160 }
161161 expected
162162}
163+
164+ /// Generates state map structure that corresponds to edges (with deltas)
165+ ///
166+ /// Each group i has state:
167+ // ('node','is', i)
168+ // ('group', j, 'seen') - for all j less than i
169+ pub fn structure_from_edges_with_state (
170+ edges : BTreeMap < i64 , i64 > ,
171+ start : i64 ,
172+ end : i64 ,
173+ ) -> BTreeMap < i64 , StateGroupEntry > {
174+ let mut expected: BTreeMap < i64 , StateGroupEntry > = BTreeMap :: new ( ) ;
175+
176+ // Each group i has state:
177+ // ('node','is', i)
178+ // ('group', j, 'seen') - for all j less than i
179+ for i in start..=end {
180+ let prev = edges. get ( & i) ;
181+
182+ //change from Option<&i64> to Option<i64>
183+ let prev = prev. copied ( ) ;
184+
185+ // create a blank entry for it
186+ let mut entry = StateGroupEntry {
187+ in_range : true ,
188+ prev_state_group : prev,
189+ state_map : StateMap :: new ( ) ,
190+ } ;
191+
192+ // Add in all state between predecessor and now (non inclusive)
193+ if let Some ( p) = prev {
194+ for j in ( p + 1 ) ..i {
195+ entry
196+ . state_map
197+ . insert ( "group" , & j. to_string ( ) , "seen" . into ( ) ) ;
198+ }
199+ } else {
200+ for j in start..i {
201+ entry
202+ . state_map
203+ . insert ( "group" , & j. to_string ( ) , "seen" . into ( ) ) ;
204+ }
205+ }
206+
207+ // add in the new state for this state group
208+ entry
209+ . state_map
210+ . insert ( "group" , & i. to_string ( ) , "seen" . into ( ) ) ;
211+ entry. state_map . insert ( "node" , "is" , i. to_string ( ) . into ( ) ) ;
212+
213+ // put it into the expected map
214+ expected. insert ( i, entry) ;
215+ }
216+ expected
217+ }
0 commit comments