pub struct Cards { /* private fields */ }Expand description
The ordered card table: value -> word, in descending key order.
Python uses an OrderedDict whose insertion order (high, then mid, then
low) happens to be descending. splitnum iterates it in that order, so a
sorted Vec reproduces the semantics while allowing binary search.
Implementations§
Source§impl Cards
impl Cards
pub fn new() -> Self
pub fn insert(&mut self, key: BigInt, word: impl Into<String>)
pub fn get(&self, key: &BigInt) -> Option<&str>
Sourcepub fn iter(&self) -> impl Iterator<Item = &(BigInt, String)>
pub fn iter(&self) -> impl Iterator<Item = &(BigInt, String)>
Descending iteration, matching the Python insertion order.
Sourcepub fn iter_from(
&self,
value: &BigInt,
) -> impl Iterator<Item = &(BigInt, String)>
pub fn iter_from( &self, value: &BigInt, ) -> impl Iterator<Item = &(BigInt, String)>
Entries from the first card <= value, descending.
Python does for elem in self.cards: if elem > value: continue, an
O(n) scan that costs ~100 BigInt comparisons to reach “forty” from
10^303. Entries are sorted descending, so the first card <= value
is a binary-search partition point — identical result, O(log n).
pub fn highest(&self) -> Option<&BigInt>
pub fn is_empty(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Cards
impl RefUnwindSafe for Cards
impl Send for Cards
impl Sync for Cards
impl Unpin for Cards
impl UnsafeUnpin for Cards
impl UnwindSafe for Cards
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
Mutably borrows from an owned value. Read more