2121//! ```
2222use std:: {
2323 cmp:: Ordering ,
24- collections:: { HashMap , VecDeque } ,
24+ collections:: { HashMap , HashSet , VecDeque } ,
2525 fmt:: { Display , Formatter , Result } ,
2626 mem,
2727 ops:: Not ,
@@ -166,7 +166,6 @@ impl Display for Clause {
166166/// ```
167167pub struct Engine {
168168 assigns : Vec < LBool > , // Current assignments of variables
169- seen : Vec < bool > , // Used during conflict analysis to track seen variables
170169 reason : Vec < Option < usize > > , // Reason for each variable's assignment (index of the clause that caused the assignment)
171170 propagated_vars : Vec < usize > , // Variables that have been propagated by decision variables
172171 decision_vars : Vec < Option < usize > > , // Decision variables that caused the propagation of each variable
@@ -189,7 +188,6 @@ impl Engine {
189188 pub fn new ( ) -> Self {
190189 Engine {
191190 assigns : Vec :: new ( ) ,
192- seen : Vec :: new ( ) ,
193191 reason : Vec :: new ( ) ,
194192 propagated_vars : Vec :: new ( ) ,
195193 decision_vars : Vec :: new ( ) ,
@@ -206,7 +204,6 @@ impl Engine {
206204 pub fn add_var ( & mut self ) -> usize {
207205 let var_id = self . assigns . len ( ) ;
208206 self . assigns . push ( LBool :: Undef ) ;
209- self . seen . push ( false ) ;
210207 self . reason . push ( None ) ;
211208 self . decision_vars . push ( None ) ;
212209 self . pos_watches . push ( Vec :: new ( ) ) ;
@@ -314,7 +311,7 @@ impl Engine {
314311 }
315312
316313 fn analyze_conflict ( & mut self , mut clause : usize ) {
317- self . seen . fill ( false ) ;
314+ let mut seen = HashSet :: new ( ) ;
318315 let mut counter: usize = 0 ;
319316 let mut p: Option < ( Lit , Option < usize > ) > = None ;
320317 self . learnt . clear ( ) ;
@@ -330,8 +327,8 @@ impl Engine {
330327 continue ;
331328 }
332329
333- if !self . seen [ v ] {
334- self . seen [ v ] = true ;
330+ if !seen. contains ( & v ) {
331+ seen. insert ( v ) ;
335332 if self . decision_vars [ v] == Some ( self . decision_var ) {
336333 counter += 1 ;
337334 } else {
@@ -344,7 +341,7 @@ impl Engine {
344341 // 2. Find the next variable from the trail assigned at this level
345342 p = loop {
346343 let v = self . propagated_vars . pop ( ) . expect ( "There should be a variable to resolve away" ) ;
347- if self . seen [ v ] {
344+ if seen. contains ( & v ) {
348345 let sign = self . value ( v) == & LBool :: True ;
349346 let reason = self . reason [ v] ;
350347 self . undo ( v) ;
0 commit comments