11use crate :: strand:: CanonicalStrand ;
2- use crate :: Answer ;
2+ use crate :: { Answer , AnswerMode } ;
33use rustc_hash:: FxHashMap ;
44use std:: collections:: hash_map:: Entry ;
55use std:: collections:: VecDeque ;
@@ -40,6 +40,8 @@ pub(crate) struct Table<I: Interner> {
4040 /// Stores the active strands that we can "pull on" to find more
4141 /// answers.
4242 strands : VecDeque < CanonicalStrand < I > > ,
43+
44+ pub ( crate ) answer_mode : AnswerMode ,
4345}
4446
4547index_struct ! {
@@ -60,6 +62,7 @@ impl<I: Interner> Table<I> {
6062 floundered : false ,
6163 answers_hash : FxHashMap :: default ( ) ,
6264 strands : VecDeque :: new ( ) ,
65+ answer_mode : AnswerMode :: Complete ,
6366 }
6467 }
6568
@@ -80,20 +83,29 @@ impl<I: Interner> Table<I> {
8083 mem:: replace ( & mut self . strands , VecDeque :: new ( ) )
8184 }
8285
83- /// Remove the next strand from the queue as long as it meets the
84- /// given criteria.
85- pub ( crate ) fn dequeue_next_strand_if (
86+ pub ( crate ) fn drain_strands (
87+ & mut self ,
88+ test : impl Fn ( & CanonicalStrand < I > ) -> bool ,
89+ ) -> VecDeque < CanonicalStrand < I > > {
90+ let old = mem:: replace ( & mut self . strands , VecDeque :: new ( ) ) ;
91+ let ( test_in, test_out) : ( VecDeque < CanonicalStrand < I > > , VecDeque < CanonicalStrand < I > > ) =
92+ old. into_iter ( ) . partition ( test) ;
93+ let _ = mem:: replace ( & mut self . strands , test_out) ;
94+ test_in
95+ }
96+
97+ /// Remove the next strand from the queue that meets the given criteria
98+ pub ( crate ) fn dequeue_next_strand_that (
8699 & mut self ,
87100 test : impl Fn ( & CanonicalStrand < I > ) -> bool ,
88101 ) -> Option < CanonicalStrand < I > > {
89- let strand = self . strands . pop_front ( ) ;
90- if let Some ( strand ) = strand {
91- if test ( & strand ) {
92- return Some ( strand ) ;
93- }
94- self . strands . push_front ( strand ) ;
102+ let first = self . strands . iter ( ) . position ( test ) ;
103+ if let Some ( first ) = first {
104+ self . strands . rotate_left ( first ) ;
105+ self . strands . pop_front ( )
106+ } else {
107+ None
95108 }
96- None
97109 }
98110
99111 /// Mark the table as floundered -- this also discards all pre-existing answers,
0 commit comments