13 Oct 2021 06:33:57 UTC
- Distribution: List-Helpers-XS
- Module version: 0.17
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (0)
- Testers (59 / 5 / 34)
- KwaliteeBus factor: 1
- % Coverage
- License: unknown
- Activity24 month
- Download (10.83KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version
- COPYRIGHT AND LICENSE
List::Helpers::XS - Perl extension to provide some usefull functions with arrays
use List::Helpers::XS qw/ :shuffle :slice /; my $slice = random_slice(\@list, $size); # returns array reference, @list is partitial shuffled random_slice(\@list, $size); # @list is now truncated and shuffled shuffle(\@list); shuffle(@list); # undef value will be skipped shuffle_multi(\@list1, \@list2, undef, \@list3); # the same for tied arrays tie(@list, "MyPackage"); shuffle(@list); shuffle(\@list); my $slice = random_slice(\@list, $size); # returns array reference
This module provides some rare but usefull functions to work with arrays. It supports tied arrays.
This method receives the array and the amount of required elements to be shuffled, shuffles array's elements and returns the array reference to the new arrays with
numelements from original one.
numis equal or higher than amount of elements in array, then it won't do any work.
It doesn't shuffle the whole array, it shuffles only
numelements and returns only them. So, if you need to shuffle and get back only a part of array, then this method can be faster than others approaches.
Be aware that the original array will be shuffled too, but it won't be sliced.
In void context the original list will be truncated and shuffled.
Shuffles the provided array. Doesn't return anything.
Shuffles multiple arrays. Each array must be passed as array reference. All undefined arrays will be skipped. This method will allow you to save some time by getting rid of extra calls. You can pass so many arguments as Perl stack allows.
random_slicemethod in comparison with
List::Util::sampleshowed that current version of
random_sliceis very similar to the first ones in some cases. But in case of huge amount of iterations it starts to slow down due to some performance degradation.
So, the usage of
List::MoreUtils::samples(it's the fastest now) and
List::Util::sampleis more preferable. I'll keep
random_slicefor backward compatibility.
The benchmark results for
shuffle_huge_array List::Helpers::XS::shuffle shuffle_huge_array -- -5% List::Helpers::XS::shuffle 5% -- shuffle_array List::Helpers::XS::shuffle shuffle_array -- -4% List::Helpers::XS::shuffle 4% -- List::Util::shuffle List::Helpers::XS::shuffle List::Util::shuffle -- -63% List::Helpers::XS::shuffle 170% --
Chernenko Dmitriy, email@example.com
Copyright (C) 2021 by Dmitriy
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.26.1 or, at your option, any later version of Perl 5 you may have available.
Module Install Instructions
To install List::Helpers::XS, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install List::Helpers::XS
For more information on module installation, please visit the detailed CPAN module installation guide.