-
Notifications
You must be signed in to change notification settings - Fork 36
Closed
Labels
Milestone
Description
I have a couple of ideas to improve the work with enum sets based on my experiences with it.
Allow to get/set both Little-Endian and Big-Endian bitsets
There are already methods EnumSet::[get/set]Bitset but it only allows Big-Endian where the internally handled bitset is in Little-Endian. This adds unnecessary overhead and reduces the supported set of features.
So I propose to add methods for both versions and deprecate the old ones:
EnumSet::getBitset() : stringEnumSet::setBitset(string $bitset)EnumSet::getBinaryBitsetLE() : stringEnumSet::setBinaryBitsetLE(string $bitset)EnumSet::getBinaryBitsetBE() : stringEnumSet::setBinaryBitsetBE(string $bitset)
Add a couple of test methods
EnumSet::isEqual(EnumSet $other) : boolEnumSet::isSubsetOf(EnumSet $other) : boolEnumSet::isSupersetOf(EnumSet $other) : bool
Add methods to create another set based on two or more sets
These methods would create a clone of $this and change the bitset to not depend on implementation details of extended classes.
EnumSet::union(EnumSet ...$others) : EnumSetEnumSet::intersect(EnumSet ...$others) : EnumSetEnumSet::diff(EnumSet ...$others) : EnumSet
Add methods to convert a set back to a native PHP array
EnumSet::toArray() : Enum[]ordinal number to enumerator instanceEnumSet::toValues() : scalar[]ordinal number to enumerator valueEnumSet::toNames() : string[]ordinal number to enumerator name
Thoughts?
@prolic