You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
however, changing the signature introduces inconsistency with Perm
the map is not reused between different calls
however, placing it into Rand increases its size, and introduces a pointer in a previously pointer-free struct
Floyd's sampling algorithm does not guarantee random order, so people are required to read the docs and don't forget to Shuffle if required
potential PartialShuffle is much faster and guarantees random order (although it requires mutable slice of size n)
having all 4 of Perm, Sample, PartialShuffle and Shuffle is maybe too much
On the other hand, Sample runs in O(k) for both time and memory. Also, algorithm is simple but non-obvious (a bit like Shuffle), as is the linear-search-instead-of-map optimization.
Sample
was added in ce7c277, however there are several problematic things:Sample
was inline and thek
is constant (!); see:Perm
Rand
increases its size, and introduces a pointer in a previously pointer-free structShuffle
if requiredPartialShuffle
is much faster and guarantees random order (although it requires mutable slice of sizen
)Perm
,Sample
,PartialShuffle
andShuffle
is maybe too muchOn the other hand,
Sample
runs in O(k) for both time and memory. Also, algorithm is simple but non-obvious (a bit likeShuffle
), as is the linear-search-instead-of-map optimization.Also, with #1,
Sample
may be not required at all.The text was updated successfully, but these errors were encountered: