Closed marc-mabe closed 8 years ago
I did some changes to optimize the performance of the methods and to not reset the internal iterator position ;)
Also added the method getOrdinals() : int[]
as this offers the basic information stored in a set as array and all other get*s()
methods are based on that.
Script: https://gist.github.com/marc-mabe/a26227adf5ea1e9c96c2072bf4351ec1 Run on:
$ php bench.php
empty set getEnumerators(): 0.0085999965667725ms
empty set getValues() : 0.0090000629425049ms
empty set getNames() : 0.0085229873657227ms
full set getEnumerators() : 1.471755027771ms
full set getValues() : 1.533252954483ms
full set getNames() : 1.9099199771881ms
$ php bench.php
empty set getEnumerators(): 0.0077300071716309ms
empty set getValues() : 0.0088911056518555ms
empty set getNames() : 0.0087888240814209ms
full set getEnumerators() : 0.68992781639099ms
full set getValues() : 0.74091100692749ms
full set getNames() : 1.0174210071564ms
@prolic thanks for review :)
see #62 Add methods to convert a set into an array
EnumSet::getEnumerators() : Enum[]
EnumSet::getValues() : scalar[]
EnumSet::getNames() : string[]
@prolic I decided to use this names to be consistent with the already existing method
Enum::getEnumerators()
and I also return it just as lists so the ordinal number will not be the array key. I analyzed all my use-cases and couldn't find any where the ordinal number as array key is required. On the other hand I have some use-cases where I actually require a simple list. Also it's still simple possible to just useiterator_to_array($set)
to convert the set into an associative array with ordinal number to enumerator instance.PS: The same set of methods should also work on
EnumMap
and onEnum
(as static versions)