Skip to content

Commit

Permalink
add Bitboard::insert() mirroring HashSet::insert()
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Dec 1, 2024
1 parent 8750c79 commit d384afc
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/bitboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ impl Bitboard {
}
}

/// Adds `square`, returning whether the square was newly added.
#[must_use = "use Bitboard::add() if return value is not needed"]
#[inline]
pub fn insert(&mut self, square: Square) -> bool {
if self.contains(square) {
false
} else {
self.add(square);
true
}
}

/// Clears all squares.
#[inline]
pub fn clear(&mut self) {
Expand Down

0 comments on commit d384afc

Please sign in to comment.