File tree Expand file tree Collapse file tree 1 file changed +26
-4
lines changed Expand file tree Collapse file tree 1 file changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -184,13 +184,35 @@ impl RoaringBitmap {
184
184
& mut self ,
185
185
iterator : I ,
186
186
) -> Result < u64 , NonSortedIntegers > {
187
- let mut count = 0 ;
187
+ // Name shadowed to prevent accidentally referencing the param
188
+ let mut iterator = iterator. into_iter ( ) ;
189
+
190
+ let mut prev: u32 = match iterator. next ( ) {
191
+ None => return Ok ( 0 ) ,
192
+ Some ( first) => {
193
+ if let Some ( max) = self . max ( ) {
194
+ if first <= max {
195
+ return Err ( NonSortedIntegers { valid_until : 0 } ) ;
196
+ }
197
+ }
198
+
199
+ first
200
+ }
201
+ } ;
202
+
203
+ self . insert ( prev) ;
204
+ let mut count = 1 ;
205
+
206
+ // It is now guaranteed that so long as the values are iterator are monotonically
207
+ // increasing they must also be the greatest in the set.
188
208
189
209
for value in iterator {
190
- if self . push ( value) {
191
- count += 1 ;
192
- } else {
210
+ if value <= prev {
193
211
return Err ( NonSortedIntegers { valid_until : count } ) ;
212
+ } else {
213
+ self . insert ( value) ;
214
+ prev = value;
215
+ count += 1 ;
194
216
}
195
217
}
196
218
You can’t perform that action at this time.
0 commit comments