Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
b2program
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
general
stups
b2program
Commits
1bccad0b
Commit
1bccad0b
authored
Feb 5, 2021
by
Chris
Browse files
Options
Downloads
Patches
Plain Diff
Update BSet.py for first performance improvement.
parent
3d864091
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
btypes_primitives/src/main/python_magicstack_immutable/btypes/BSet.py
+17
-21
17 additions, 21 deletions
...tives/src/main/python_magicstack_immutable/btypes/BSet.py
with
17 additions
and
21 deletions
btypes_primitives/src/main/python_magicstack_immutable/btypes/BSet.py
+
17
−
21
View file @
1bccad0b
...
@@ -12,20 +12,15 @@ class BSet:
...
@@ -12,20 +12,15 @@ class BSet:
if
len
(
args
)
==
1
and
type
(
args
[
0
])
is
immutables
.
Map
:
if
len
(
args
)
==
1
and
type
(
args
[
0
])
is
immutables
.
Map
:
self
.
__set
=
args
[
0
]
self
.
__set
=
args
[
0
]
else
:
else
:
_set
=
{
x
:
x
for
x
in
args
}
self
.
__set
=
immutables
.
Map
({
x
:
x
for
x
in
args
})
self
.
__set
=
immutables
.
Map
(
_set
)
def
__str__
(
self
)
->
'
str
'
:
def
__str__
(
self
)
->
'
str
'
:
return
'
{
'
+
'
,
'
.
join
([
str
(
x
)
for
x
in
self
.
__set
])
+
'
}
'
return
'
{
'
+
'
,
'
.
join
([
str
(
x
)
for
x
in
self
.
__set
])
+
'
}
'
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
if
self
is
other
:
if
not
isinstance
(
other
,
BSet
):
return
True
if
other
is
None
or
type
(
self
)
!=
type
(
other
):
return
False
if
not
self
.
__set
==
other
.
__set
:
return
False
return
False
return
True
return
self
.
__set
==
other
.
__set
def
__ne__
(
self
,
other
):
def
__ne__
(
self
,
other
):
return
not
self
.
__eq__
(
other
)
return
not
self
.
__eq__
(
other
)
...
@@ -33,14 +28,17 @@ class BSet:
...
@@ -33,14 +28,17 @@ class BSet:
def
__len__
(
self
):
def
__len__
(
self
):
return
len
(
self
.
__set
)
return
len
(
self
.
__set
)
def
__contains__
(
self
,
item
):
return
item
in
self
.
__set
def
union
(
self
,
other
=
None
):
def
union
(
self
,
other
=
None
):
if
other
is
None
:
if
other
is
None
:
if
len
(
self
.
__set
)
==
0
:
if
len
(
self
.
__set
)
==
0
:
return
BSet
()
return
BSet
()
elif
typ
e
(
next
(
iter
(
self
.
__set
))
)
==
BSet
:
elif
isinstanc
e
(
next
(
iter
(
self
.
__set
))
,
BSet
)
:
return
reduce
(
lambda
a
,
e
:
a
.
update
(
e
),
self
,
BSet
(
))
return
BSet
(
reduce
(
lambda
a
,
e
:
a
.
update
(
e
.
getSet
()),
self
,
immutables
.
Map
()
))
elif
typ
e
(
next
(
iter
(
self
.
__set
))
)
==
BRelation
:
elif
isinstanc
e
(
next
(
iter
(
self
.
__set
))
,
BRelation
)
:
return
reduce
(
lambda
a
,
e
:
a
.
u
pdate
(
e
),
self
,
BRelation
())
return
reduce
(
lambda
a
,
e
:
a
.
u
nion
(
e
),
self
,
BRelation
())
return
BSet
(
self
.
__set
.
update
(
other
.
getSet
()))
return
BSet
(
self
.
__set
.
update
(
other
.
getSet
()))
...
@@ -48,22 +46,20 @@ class BSet:
...
@@ -48,22 +46,20 @@ class BSet:
if
other
is
None
:
if
other
is
None
:
if
len
(
self
.
__set
)
==
0
:
if
len
(
self
.
__set
)
==
0
:
return
BSet
()
return
BSet
()
elif
typ
e
(
next
(
iter
(
self
.
__set
))
)
==
BSet
:
elif
isinstanc
e
(
next
(
iter
(
self
.
__set
))
,
BSet
)
:
return
reduce
(
lambda
a
,
e
:
a
.
intersect
(
e
),
self
,
BSet
())
return
reduce
(
lambda
a
,
e
:
a
.
intersect
(
e
),
self
,
BSet
())
elif
typ
e
(
next
(
iter
(
self
.
__set
))
)
==
BRelation
:
elif
isinstanc
e
(
next
(
iter
(
self
.
__set
))
,
BRelation
)
:
return
reduce
(
lambda
a
,
e
:
a
.
intersect
(
e
),
self
,
BRelation
())
return
reduce
(
lambda
a
,
e
:
a
.
intersect
(
e
),
self
,
BRelation
())
_set
=
self
.
__set
_set
=
self
.
__set
for
element
in
_set
:
other_set
=
other
.
__set
if
not
element
in
other
.
__set
:
_set
=
reduce
(
lambda
current_set
,
el
:
current_set
.
delete
(
el
)
if
el
not
in
other_set
else
current_set
,
_set
,
_set
)
_set
=
_set
.
delete
(
element
)
return
BSet
(
_set
)
return
BSet
(
_set
)
def
difference
(
self
,
other
:
'
BSet
'
)
->
'
BSet
'
:
def
difference
(
self
,
other
:
'
BSet
'
)
->
'
BSet
'
:
_set
=
self
.
__set
_set
=
self
.
__set
for
element
in
other
.
__set
:
other_set
=
other
.
__set
if
element
in
_set
:
_set
=
reduce
(
lambda
current_set
,
el
:
current_set
.
delete
(
el
)
if
el
in
_set
else
current_set
,
other_set
,
_set
)
_set
=
_set
.
delete
(
element
)
return
BSet
(
_set
)
return
BSet
(
_set
)
def
card
(
self
)
->
'
BInteger
'
:
def
card
(
self
)
->
'
BInteger
'
:
...
@@ -246,7 +242,7 @@ class BSet:
...
@@ -246,7 +242,7 @@ class BSet:
@staticmethod
@staticmethod
def
interval
(
a
:
'
BInteger
'
,
b
:
'
BInteger
'
)
->
'
BSet
'
:
def
interval
(
a
:
'
BInteger
'
,
b
:
'
BInteger
'
)
->
'
BSet
'
:
r
=
list
(
map
(
BInteger
,
range
(
a
.
intValue
(),
b
.
intValue
()
+
1
))
)
r
=
map
(
BInteger
,
range
(
a
.
intValue
(),
b
.
intValue
()
+
1
))
return
BSet
(
*
r
)
return
BSet
(
*
r
)
def
__hash__
(
self
):
def
__hash__
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment