Skip to content

Commit 3710be4

Browse files
committed
Move fields sorting step to boundaries of the Board type
1 parent 45d0afa commit 3710be4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

gomori/src/board.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ pub struct Board {
2626
/// There is exactly one entry in this list for every field with at least one card on it.
2727
///
2828
/// The `bbox` and `bitboards` fields are derived from this list.
29+
///
30+
/// Note: This is not guaranteed to be sorted.
2931
fields: Vec<(i8, i8, CompactField)>,
3032
/// The center coordinate for all bitboards produced by this board.
3133
/// Using a consistent center coordinate enables binary operations like bitwise or.
@@ -298,7 +300,8 @@ impl Board {
298300
}
299301

300302
pub fn to_fields_vec(&self) -> Vec<Field> {
301-
self.fields
303+
let mut fields_vec: Vec<Field> = self
304+
.fields
302305
.iter()
303306
.filter_map(|&(i, j, cf)| {
304307
if cf.is_empty() {
@@ -312,7 +315,9 @@ impl Board {
312315
})
313316
}
314317
})
315-
.collect()
318+
.collect();
319+
fields_vec.sort_by_key(|f| (f.i, f.j));
320+
fields_vec
316321
}
317322

318323
// Internal helper function to compute fields where the top cards are flipped face-down.
@@ -419,7 +424,6 @@ impl Diff {
419424
bitboards[self.new_card.suit as usize].insert(self.new_card_i, self.new_card_j);
420425
}
421426
new_fields.push((self.new_card_i, self.new_card_j, new_field));
422-
new_fields.sort_by_key(|&(i, j, _)| (i, j));
423427
}
424428

425429
Board {

0 commit comments

Comments
 (0)