Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup completions/guide code #38

Closed
wants to merge 2 commits into from

Conversation

poke1024
Copy link

@poke1024 poke1024 commented Apr 22, 2019

The relevant commit here is:
efd9b7b

This is a proposal to cleanup the duplicate completions code.

This would help in integrating #37 in a proper way.

Contains three changes:

(1) DAWG now gets a param completions which lets any base DAWG create a guide
(2) Completions are delegated to a new PyCompletions class; this helps avoid code duplication (e.g. in IntCompletionDAWG). Also, PyCompletions will create the underlying Completions instance in its constructor, which will reduce memory allocations (in master, this underlying class is recreated on each function call requesting a completion). At the same time, you can create multiple instances for multiple threads.
(3) loading and storing are adjusted; as a nice aside, you can load a DAWG and it will automatically load completions if they were stored

Here's an example with the changed API that now involved a completer() method:

import dawg
keys = ["weather", "this", "there", "thus", "another"]
d = dawg.CompletionDAWG(keys)
print(d.completer().keys("th"))

I'd prefer to change dawg.CompletionDAWG to dawg.CompletionsDAWG (added s) and d.completions() for consistency (see poke1024@a50edcd).

tested with python 3.7.3 and python 2.7.10
@poke1024
Copy link
Author

Continuing to work on this on a fork.

@poke1024 poke1024 closed this Apr 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant