@@ -93,57 +93,83 @@ where
9393 } ;
9494 }
9595
96- let mut first = true ;
97- for idx in set_in_self. iter ( ) {
98- let delim = if first {
99- "\u{001f} +"
100- } else if f. alternate ( ) {
101- "\n \u{001f} +"
102- } else {
103- ", "
104- } ;
96+ fmt_diff ( & set_in_self, & cleared_in_self, ctxt, f)
97+ }
98+ }
10599
106- write ! ( f, "{}" , delim) ?;
107- idx. fmt_with ( ctxt, f) ?;
108- first = false ;
109- }
100+ impl < T , C > DebugWithContext < C > for ChunkedBitSet < T >
101+ where
102+ T : Idx + DebugWithContext < C > ,
103+ {
104+ fn fmt_with ( & self , ctxt : & C , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
105+ f. debug_set ( ) . entries ( self . iter ( ) . map ( |i| DebugWithAdapter { this : i, ctxt } ) ) . finish ( )
106+ }
110107
111- if !f. alternate ( ) {
112- first = true ;
113- if !set_in_self. is_empty ( ) && !cleared_in_self. is_empty ( ) {
114- write ! ( f, "\t " ) ?;
115- }
116- }
108+ fn fmt_diff_with ( & self , old : & Self , ctxt : & C , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
109+ let size = self . domain_size ( ) ;
110+ assert_eq ! ( size, old. domain_size( ) ) ;
117111
118- for idx in cleared_in_self. iter ( ) {
119- let delim = if first {
120- "\u{001f} -"
121- } else if f. alternate ( ) {
122- "\n \u{001f} -"
123- } else {
124- ", "
125- } ;
112+ let mut set_in_self = HybridBitSet :: new_empty ( size) ;
113+ let mut cleared_in_self = HybridBitSet :: new_empty ( size) ;
126114
127- write ! ( f, "{}" , delim) ?;
128- idx. fmt_with ( ctxt, f) ?;
129- first = false ;
115+ for i in ( 0 ..size) . map ( T :: new) {
116+ match ( self . contains ( i) , old. contains ( i) ) {
117+ ( true , false ) => set_in_self. insert ( i) ,
118+ ( false , true ) => cleared_in_self. insert ( i) ,
119+ _ => continue ,
120+ } ;
130121 }
131122
132- Ok ( ( ) )
123+ fmt_diff ( & set_in_self , & cleared_in_self , ctxt , f )
133124 }
134125}
135126
136- impl < T , C > DebugWithContext < C > for ChunkedBitSet < T >
127+ fn fmt_diff < T , C > (
128+ inserted : & HybridBitSet < T > ,
129+ removed : & HybridBitSet < T > ,
130+ ctxt : & C ,
131+ f : & mut fmt:: Formatter < ' _ > ,
132+ ) -> fmt:: Result
137133where
138134 T : Idx + DebugWithContext < C > ,
139135{
140- fn fmt_with ( & self , _ctxt : & C , _f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
141- unimplemented ! ( "implement when/if needed" ) ;
136+ let mut first = true ;
137+ for idx in inserted. iter ( ) {
138+ let delim = if first {
139+ "\u{001f} +"
140+ } else if f. alternate ( ) {
141+ "\n \u{001f} +"
142+ } else {
143+ ", "
144+ } ;
145+
146+ write ! ( f, "{}" , delim) ?;
147+ idx. fmt_with ( ctxt, f) ?;
148+ first = false ;
149+ }
150+
151+ if !f. alternate ( ) {
152+ first = true ;
153+ if !inserted. is_empty ( ) && !removed. is_empty ( ) {
154+ write ! ( f, "\t " ) ?;
155+ }
142156 }
143157
144- fn fmt_diff_with ( & self , _old : & Self , _ctxt : & C , _f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
145- unimplemented ! ( "implement when/if needed" ) ;
158+ for idx in removed. iter ( ) {
159+ let delim = if first {
160+ "\u{001f} -"
161+ } else if f. alternate ( ) {
162+ "\n \u{001f} -"
163+ } else {
164+ ", "
165+ } ;
166+
167+ write ! ( f, "{}" , delim) ?;
168+ idx. fmt_with ( ctxt, f) ?;
169+ first = false ;
146170 }
171+
172+ Ok ( ( ) )
147173}
148174
149175impl < T , C > DebugWithContext < C > for & ' _ T
0 commit comments