pub struct Card64(/* private fields */);Expand description
A 64-bit representation of a set of playing cards using bitwise operations.
Card64 efficiently stores multiple cards in a single u64 value, where each bit represents a specific card. This allows for fast set operations like union, intersection, and membership testing using bitwise operations.
Card Set
§Memory Layout:
[63, 48]: xxxAKQJT 98765432 // Club
[47, 32]: xxxAKQJT 98765432 // Diamond
[31, 16]: xxxAKQJT 98765432 // Heart
[15, 0]: xxxAKQJT 98765432 // Spade, x: unusedImplementations§
Source§impl Card64
impl Card64
Sourcepub const fn is_empty(self) -> bool
pub const fn is_empty(self) -> bool
Checks whether all rank masks are unset
§Examples
use open_pql::{Card, Card64, Rank::*, Suit::*};
let c64: Card64 = Card64::from(Card::new(R2, S));
assert!(!c64.is_empty());Sourcepub fn contains(self, other: Self) -> bool
pub fn contains(self, other: Self) -> bool
checks whether another Card64 is a subset
§Examples
use open_pql::{Card, Card64, Rank::*, Suit::*};
let c64_2s: Card64 = Card64::from(Card::new(R2, S));
let c64_2h: Card64 = Card64::from(Card::new(R2, H));
let c64_2s_2h: Card64 = c64_2s | c64_2h;
assert!(c64_2s_2h.contains(c64_2h));
assert!(!c64_2s.contains(c64_2h));Sourcepub const fn contains_card(self, c: Card) -> bool
pub const fn contains_card(self, c: Card) -> bool
Sourcepub const fn count(&self) -> PQLCardCount
pub const fn count(&self) -> PQLCardCount
Returns the number of marked cards
§Examples
use open_pql::{Card, Card64, Rank::*, Suit::*};
let c64: Card64 = Card64::from(Card::new(R2, S));
assert_eq!(c64.count(), 1);Sourcepub const fn count_by_rank(self, r: Rank) -> PQLCardCount
pub const fn count_by_rank(self, r: Rank) -> PQLCardCount
Returns the number of marked cards of rank r
§Examples
use open_pql::{Card, Card64, Rank::*, Suit::*};
let c64: Card64 = Card64::all();
assert_eq!(c64.count_by_rank(RA), 4);Sourcepub const fn count_by_suit(self, s: Suit) -> PQLCardCount
pub const fn count_by_suit(self, s: Suit) -> PQLCardCount
Returns the number of marked cards of suit s
§Examples
use open_pql::{Card, Card64, Rank::*, Suit::*};
let c64: Card64 = Card64::all();
assert_eq!(c64.count_by_suit(D), 13);Sourcepub const fn from_ranks(rs: Rank16) -> Self
pub const fn from_ranks(rs: Rank16) -> Self
Creates a Card64 with all four cards of each rank in the given Rank16.
§Examples
use open_pql::{Card64, Rank::*, Rank16};
let ranks = Rank16::from([RA, RK].as_ref());
let c64 = Card64::from_ranks(ranks);
assert_eq!(c64.count_by_rank(RA), 4);
assert_eq!(c64.count_by_rank(RK), 4);
assert_eq!(c64.count_by_rank(RQ), 0);Sourcepub const fn ranks(self) -> Rank16
pub const fn ranks(self) -> Rank16
Returns a Rank16 containing all ranks that have at least one card marked.
§Examples
use open_pql::{Card, Card64, Rank::*, Suit::*};
let c64 = Card64::from([Card::new(RA, S), Card::new(RK, H)].as_ref());
let ranks = c64.ranks();
assert!(ranks.contains_rank(RA));
assert!(ranks.contains_rank(RK));
assert!(!ranks.contains_rank(RQ));Sourcepub const fn iter(self) -> CardIter ⓘ
pub const fn iter(self) -> CardIter ⓘ
Returns an iterator over all cards in this set.
§Examples
use open_pql::{Card, Card64, Rank::*, Suit::*};
let c64 = Card64::from([Card::new(RA, S), Card::new(RK, H)].as_ref());
let cards: Vec<Card> = c64.iter().collect();
assert_eq!(cards.len(), 2);Sourcepub const fn iter_ranks(self) -> Rank16Iter ⓘ
pub const fn iter_ranks(self) -> Rank16Iter ⓘ
Returns an iterator over the ranks in each suit.
The iterator yields tuples of (Rank16, Suit) for each suit in the order S, H, D, C.
§Examples
use open_pql::{Card, Card64, Rank::*, Suit::*};
let c64 = Card64::from([Card::new(RA, S), Card::new(RK, H)].as_ref());
let ranks: Vec<_> = c64.iter_ranks().collect();
assert_eq!(ranks.len(), 4);
assert!(ranks[0].0.contains_rank(RA)); // Spades
assert!(ranks[1].0.contains_rank(RK)); // HeartsTrait Implementations§
Source§impl BitAndAssign for Card64
impl BitAndAssign for Card64
Source§fn bitand_assign(&mut self, rhs: Card64)
fn bitand_assign(&mut self, rhs: Card64)
&= operation. Read moreSource§impl BitOrAssign for Card64
impl BitOrAssign for Card64
Source§fn bitor_assign(&mut self, rhs: Card64)
fn bitor_assign(&mut self, rhs: Card64)
|= operation. Read moreimpl Copy for Card64
impl Eq for Card64
impl StructuralPartialEq for Card64
Auto Trait Implementations§
impl Freeze for Card64
impl RefUnwindSafe for Card64
impl Send for Card64
impl Sync for Card64
impl Unpin for Card64
impl UnwindSafe for Card64
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more