Skip to content

Commit

Permalink
earley: minor speedup use list instead of set to avoid hashing overhe…
Browse files Browse the repository at this point in the history
…ad when tracking waiting_for
  • Loading branch information
timvieira committed Jun 29, 2024
1 parent 5a1ad93 commit 540db0b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions genparse/experimental/earley.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, k):

# Within column J, this datastructure maps nonterminals Y to a set of items
# Y => {(I, X, Ys) | phrase(I,X/[Y],J) ≠ 0}
self.waiting_for = defaultdict(set)
self.waiting_for = defaultdict(list)

# priority queue used when first filling the column
# self.Q = pdict()
Expand Down Expand Up @@ -234,7 +234,7 @@ def _update(self, col, I, X, Ys, value):
item = (I, X, Ys)
was = col.i_chart.get(item)
if was is None:
col.waiting_for[self.first_Ys[Ys]].add(item)
col.waiting_for[self.first_Ys[Ys]].append(item)
col.i_chart[item] = value
else:
col.i_chart[item] = was + value
Expand Down

0 comments on commit 540db0b

Please sign in to comment.