Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
fja
eval
Commits
b877176d
Commit
b877176d
authored
Apr 13, 2021
by
Vladimír Štill
Browse files
lib: Add slots to CFG data structures
parent
c9d312df
Pipeline
#79989
passed with stage
in 1 minute and 34 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/grammars_cfg.py
View file @
b877176d
...
...
@@ -111,6 +111,8 @@ def zip_fill(seqa: Iterable[TA], seqb: Iterable[TB], sentinel: bool = False) \
class
ChangeTracker
:
__slots__
=
[
"_changed"
]
def
__init__
(
self
):
self
.
_changed
=
True
...
...
@@ -135,6 +137,8 @@ class CFG:
Word
=
Tuple
[
Terminal
,
...]
Rules
=
Dict
[
Nonterminal
,
Set
[
Production
]]
__slots__
=
[
"nonterminals"
,
"terminals"
,
"rules"
,
"init"
]
def
__init__
(
self
,
nonterminals
:
Set
[
Nonterminal
],
terminals
:
Set
[
Terminal
],
rules
:
CFG
.
Rules
,
...
...
@@ -651,6 +655,8 @@ class WordGenerator:
CountMap
=
Dict
[
Nonterminal
,
int
]
ProdCountMap
=
Dict
[
CFG
.
Production
,
int
]
__slots__
=
[
"cfg"
,
"_seen"
,
"_stack"
,
"_cur_lenght"
,
"_next_length"
,
"last"
,
"counts"
,
"prod_counts"
]
def
__init__
(
self
,
cfg
:
CFG
):
self
.
cfg
=
cfg
.
proper
()
self
.
_seen
:
Set
[
CFG
.
Symbols
]
=
set
()
...
...
@@ -832,6 +838,9 @@ class WordGenerator:
class
CachedCYK
:
__slots__
=
[
"cfg"
,
"cache"
]
def
__init__
(
self
,
cfg
:
CFG
):
self
.
cfg
=
cfg
.
cnf
()
self
.
cache
:
Dict
[
CFG
.
Word
,
Set
[
Nonterminal
]]
=
dict
()
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment