Skip to content

Commit f05c69a

Browse files
committed
Immutable EnumSet
1 parent db8599f commit f05c69a

File tree

5 files changed

+783
-192
lines changed

5 files changed

+783
-192
lines changed

bench/EnumSet32Bench.php

Lines changed: 100 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,40 +48,105 @@ public function init()
4848
$this->enumerators = Enum32::getEnumerators();
4949

5050
$this->emptySet = new EnumSet(Enum32::class);
51-
$this->fullSet = new EnumSet(Enum32::class);
51+
$this->fullSet = new EnumSet(Enum32::class, $this->enumerators);
52+
}
53+
54+
public function benchAttachEnumerator()
55+
{
5256
foreach ($this->enumerators as $enumerator) {
53-
$this->fullSet->attach($enumerator);
57+
$this->emptySet->attachEnumerator($enumerator);
5458
}
5559
}
5660

57-
public function benchAttachEnumerator()
61+
public function benchWithEnumerator()
5862
{
5963
foreach ($this->enumerators as $enumerator) {
60-
$this->emptySet->attach($enumerator);
64+
$this->emptySet->withEnumerator($enumerator);
65+
}
66+
}
67+
68+
public function benchAttachEnumerators()
69+
{
70+
$this->emptySet->withEnumerators($this->enumerators);
71+
}
72+
73+
public function benchWithEnumerators()
74+
{
75+
$this->emptySet->attachEnumerators($this->enumerators);
76+
}
77+
78+
public function benchWithValue()
79+
{
80+
foreach ($this->values as $value) {
81+
$this->emptySet->withEnumerator($value);
6182
}
6283
}
6384

6485
public function benchAttachValue()
6586
{
6687
foreach ($this->values as $value) {
67-
$this->emptySet->attach($value);
88+
$this->emptySet->attachEnumerator($value);
6889
}
6990
}
7091

92+
public function benchAttachValues()
93+
{
94+
$this->emptySet->attachEnumerators($this->values);
95+
}
96+
97+
public function benchWithValues()
98+
{
99+
$this->emptySet->withEnumerators($this->values);
100+
}
101+
71102
public function benchDetachEnumerator()
72103
{
73104
foreach ($this->enumerators as $enumerator) {
74-
$this->fullSet->detach($enumerator);
105+
$this->fullSet->detachEnumerator($enumerator);
75106
}
76107
}
77108

109+
public function benchWithoutEnumerator()
110+
{
111+
foreach ($this->enumerators as $enumerator) {
112+
$this->fullSet->withoutEnumerator($enumerator);
113+
}
114+
}
115+
116+
public function benchDetachEnumerators()
117+
{
118+
$this->fullSet->detachEnumerators($this->enumerators);
119+
}
120+
121+
public function benchWithoutEnumerators()
122+
{
123+
$this->fullSet->withoutEnumerators($this->enumerators);
124+
}
125+
78126
public function benchDetachValue()
79127
{
80128
foreach ($this->values as $value) {
81-
$this->fullSet->detach($value);
129+
$this->fullSet->detachEnumerator($value);
130+
}
131+
}
132+
133+
public function benchWithoutValue()
134+
{
135+
foreach ($this->values as $value) {
136+
$this->fullSet->withoutEnumerator($value);
82137
}
83138
}
84139

140+
public function benchDetachValues()
141+
{
142+
$this->fullSet->detachEnumerators($this->values);
143+
}
144+
145+
public function benchWithoutValues()
146+
{
147+
$this->fullSet->withoutEnumerators($this->values);
148+
}
149+
85150
public function benchContainsEnumerator()
86151
{
87152
foreach ($this->enumerators as $enumerator) {
@@ -135,24 +200,44 @@ public function benchIsSuperset()
135200
$this->fullSet->isSuperset($this->fullSet);
136201
}
137202

138-
public function benchUnion()
203+
public function benchSetUnion()
204+
{
205+
$this->fullSet->setUnion($this->emptySet);
206+
}
207+
208+
public function benchWithUnion()
209+
{
210+
$this->fullSet->withUnion($this->emptySet);
211+
}
212+
213+
public function benchSetIntersect()
214+
{
215+
$this->fullSet->setIntersect($this->emptySet);
216+
}
217+
218+
public function benchWithIntersect()
219+
{
220+
$this->fullSet->withIntersect($this->emptySet);
221+
}
222+
223+
public function benchSetDiff()
139224
{
140-
$this->fullSet->union($this->emptySet);
225+
$this->fullSet->setDiff($this->emptySet);
141226
}
142227

143-
public function benchIntersect()
228+
public function benchWithDiff()
144229
{
145-
$this->fullSet->intersect($this->emptySet);
230+
$this->fullSet->withDiff($this->emptySet);
146231
}
147232

148-
public function benchDiff()
233+
public function benchSetSymDiff()
149234
{
150-
$this->fullSet->diff($this->emptySet);
235+
$this->fullSet->setSymDiff($this->emptySet);
151236
}
152237

153-
public function benchSymDiff()
238+
public function benchWithSymDiff()
154239
{
155-
$this->fullSet->symDiff($this->emptySet);
240+
$this->fullSet->withSymDiff($this->emptySet);
156241
}
157242

158243
public function benchGetOrdinalsFull()

bench/EnumSet66Bench.php

Lines changed: 100 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,40 +48,105 @@ public function init()
4848
$this->enumerators = Enum66::getEnumerators();
4949

5050
$this->emptySet = new EnumSet(Enum66::class);
51-
$this->fullSet = new EnumSet(Enum66::class);
51+
$this->fullSet = new EnumSet(Enum66::class, $this->enumerators);
52+
}
53+
54+
public function benchAttachEnumerator()
55+
{
5256
foreach ($this->enumerators as $enumerator) {
53-
$this->fullSet->attach($enumerator);
57+
$this->emptySet->attachEnumerator($enumerator);
5458
}
5559
}
5660

57-
public function benchAttachEnumerator()
61+
public function benchWithEnumerator()
5862
{
5963
foreach ($this->enumerators as $enumerator) {
60-
$this->emptySet->attach($enumerator);
64+
$this->emptySet->withEnumerator($enumerator);
6165
}
6266
}
6367

68+
public function benchAttachEnumerators()
69+
{
70+
$this->emptySet->attachEnumerators($this->enumerators);
71+
}
72+
73+
public function benchWithEnumerators()
74+
{
75+
$this->emptySet->withEnumerators($this->enumerators);
76+
}
77+
6478
public function benchAttachValue()
6579
{
6680
foreach ($this->values as $value) {
67-
$this->emptySet->attach($value);
81+
$this->emptySet->attachEnumerator($value);
82+
}
83+
}
84+
85+
public function benchWithValue()
86+
{
87+
foreach ($this->values as $value) {
88+
$this->emptySet->withEnumerator($value);
6889
}
6990
}
7091

92+
public function benchAttachValues()
93+
{
94+
$this->emptySet->attachEnumerators($this->values);
95+
}
96+
97+
public function benchWithValues()
98+
{
99+
$this->emptySet->withEnumerators($this->values);
100+
}
101+
71102
public function benchDetachEnumerator()
72103
{
73104
foreach ($this->enumerators as $enumerator) {
74-
$this->emptySet->detach($enumerator);
105+
$this->emptySet->detachEnumerator($enumerator);
75106
}
76107
}
77108

109+
public function benchWithoutEnumerator()
110+
{
111+
foreach ($this->enumerators as $enumerator) {
112+
$this->emptySet->withoutEnumerator($enumerator);
113+
}
114+
}
115+
116+
public function benchDetachEnumerators()
117+
{
118+
$this->emptySet->detachEnumerators($this->enumerators);
119+
}
120+
121+
public function benchWithoutEnumerators()
122+
{
123+
$this->emptySet->withoutEnumerators($this->enumerators);
124+
}
125+
78126
public function benchDetachValue()
79127
{
80128
foreach ($this->values as $value) {
81-
$this->emptySet->detach($value);
129+
$this->emptySet->detachEnumerator($value);
130+
}
131+
}
132+
133+
public function benchWithoutValue()
134+
{
135+
foreach ($this->values as $value) {
136+
$this->emptySet->withoutEnumerator($value);
82137
}
83138
}
84139

140+
public function benchDetachValues()
141+
{
142+
$this->emptySet->detachEnumerators($this->values);
143+
}
144+
145+
public function benchWithoutValues()
146+
{
147+
$this->emptySet->withoutEnumerators($this->values);
148+
}
149+
85150
public function benchContainsEnumerator()
86151
{
87152
foreach ($this->enumerators as $enumerator) {
@@ -135,24 +200,44 @@ public function benchIsSuperset()
135200
$this->fullSet->isSuperset($this->fullSet);
136201
}
137202

138-
public function benchUnion()
203+
public function benchSetUnion()
204+
{
205+
$this->fullSet->setUnion($this->emptySet);
206+
}
207+
208+
public function benchWithUnion()
209+
{
210+
$this->fullSet->withUnion($this->emptySet);
211+
}
212+
213+
public function benchSetIntersect()
214+
{
215+
$this->fullSet->setIntersect($this->emptySet);
216+
}
217+
218+
public function benchWithIntersect()
219+
{
220+
$this->fullSet->withIntersect($this->emptySet);
221+
}
222+
223+
public function benchSetDiff()
139224
{
140-
$this->fullSet->union($this->emptySet);
225+
$this->fullSet->setDiff($this->emptySet);
141226
}
142227

143-
public function benchIntersect()
228+
public function benchWithDiff()
144229
{
145-
$this->fullSet->intersect($this->emptySet);
230+
$this->fullSet->withDiff($this->emptySet);
146231
}
147232

148-
public function benchDiff()
233+
public function benchSetSymDiff()
149234
{
150-
$this->fullSet->diff($this->emptySet);
235+
$this->fullSet->setSymDiff($this->emptySet);
151236
}
152237

153-
public function benchSymDiff()
238+
public function benchWithSymDiff()
154239
{
155-
$this->fullSet->symDiff($this->emptySet);
240+
$this->fullSet->withSymDiff($this->emptySet);
156241
}
157242

158243
public function benchGetOrdinalsFull()

0 commit comments

Comments
 (0)