Skip to content

new EnumSet methods #62

@marc-mabe

Description

@marc-mabe

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() : string
  • EnumSet::setBitset(string $bitset)
  • EnumSet::getBinaryBitsetLE() : string
  • EnumSet::setBinaryBitsetLE(string $bitset)
  • EnumSet::getBinaryBitsetBE() : string
  • EnumSet::setBinaryBitsetBE(string $bitset)

Add a couple of test methods

  • EnumSet::isEqual(EnumSet $other) : bool
  • EnumSet::isSubsetOf(EnumSet $other) : bool
  • EnumSet::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) : EnumSet
  • EnumSet::intersect(EnumSet ...$others) : EnumSet
  • EnumSet::diff(EnumSet ...$others) : EnumSet

Add methods to convert a set back to a native PHP array

  • EnumSet::toArray() : Enum[] ordinal number to enumerator instance
  • EnumSet::toValues() : scalar[] ordinal number to enumerator value
  • EnumSet::toNames() : string[] ordinal number to enumerator name

Thoughts?
@prolic

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions