Closed SBuercklin closed 1 year ago
Thanks, @SBuercklin, for the changes, they look great! I'm happy to merge, but could you squash the commits first?
It's a very space-efficient implementation of a standard 52-card deck, and I'm looking forward to playing around with it :)
It is! My original implementation was very space inefficient, and then I borrowed basically most of the card representation design from Stephan Karpinski's (unregistered) Cards.jl, so credit to him for the great design 🙂
FWIW, the Allocations
test is failing for me locally on 1.7.3
but passing on LTS 1.6.6
. I get 352 instead of 304 for alloc
.
I haven't looked too deeply into why that might be happening yet, but if you have any ideas it could be worth opening an issue upstream. If I get a chance tomorrow I'll ask about it on the Slack.
FWIW, the
Allocations
test is failing for me locally on1.7.3
but passing on LTS1.6.6
. I get 352 instead of 304 foralloc
.
Same here, I assume it's just a small upstream regression. I'm not too worried about it, I think I was just trying to be extra careful about allocations while I was trying to optimize some downstream packages. I'm monkey patching the test in #28 for now.
Merging #27 (36e7d17) into main (b42ea56) will decrease coverage by
4.50%
. The diff coverage is42.85%
.
@@ Coverage Diff @@
## main #27 +/- ##
==========================================
- Coverage 98.80% 94.31% -4.50%
==========================================
Files 2 2
Lines 84 88 +4
==========================================
Hits 83 83
- Misses 1 5 +4
Impacted Files | Coverage Δ | |
---|---|---|
src/PlayingCards.jl | 94.20% <42.85%> (-5.80%) |
:arrow_down: |
Not sure why I didn't merge that earlier!
This PR makes two main changes:
shuffle!
(and nowshuffle
as well) can be passed anAbstractRNG
to let the user define their own RNG. If no RNG is provided, the default RNG is used instead. I also rewroteshuffle!
to use the in-placeshuffle!(::Vector)
method so that shuffling the deck is non-allocating.Along with that, I wrote an out-of-place
shuffle
method which allows you to retain your original deck.I also changed the type parameterization for
Deck{<:Vector}
toDeck{<:AbstractVector{Card}
. This forces the contents ofDeck
to be a vector ofCard
s, where before theDeck
could contain anyVector
. Using anAbstractVector
also lets users use an alternative vector type, like anSVector
to stack-allocate theDeck
.I'm happy to throw out the
Deck{<:Vector}
change; I only included it because I didn't feel like a second PR was necessary. Theshuffle
RNG changes are my primary interest.I also wanted to say thanks for putting this package together. It's a very space-efficient implementation of a standard 52-card deck, and I'm looking forward to playing around with it :)