Skip to content

Commit d384afc

Browse files
committed
add Bitboard::insert() mirroring HashSet::insert()
1 parent 8750c79 commit d384afc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/bitboard.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ impl Bitboard {
168168
}
169169
}
170170

171+
/// Adds `square`, returning whether the square was newly added.
172+
#[must_use = "use Bitboard::add() if return value is not needed"]
173+
#[inline]
174+
pub fn insert(&mut self, square: Square) -> bool {
175+
if self.contains(square) {
176+
false
177+
} else {
178+
self.add(square);
179+
true
180+
}
181+
}
182+
171183
/// Clears all squares.
172184
#[inline]
173185
pub fn clear(&mut self) {

0 commit comments

Comments
 (0)