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

Code for issues 56 and 57, including tests #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hallvard
Copy link

I've implemented support for replaceable Tokenizer and handling unknown variables, as suggested by issues 56 and 57.

@hallvard
Copy link
Author

@fasseg Any chance a replaceable Tokenizer may be accepted, without the support for handling unknown variables?

private Collection<String> undefinedVariables = null;

public void allowUndefinedVariables(boolean allow) {
this.undefinedVariables = (allow ? new ArrayList<String>() : null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could use HashSet, or rather LinkedHashSet if you want to preserve tokens order. ArrayList will consume less memory but HashSet will perform better. I'm not sure what is more important here.

The ArrayList:

  • contains - O(N)
  • add - O(1)

The HashSet or LinkedHashSet:

  • contains - O(1)
  • add - O(1)

But also, with HashSet you could not check contains(name) since Set guarantees Strings uniqueness on add(name) so the number of operations is smaller.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ArrayList's add can be O(N), if it needs to reallocate the underlying array. Anyway, it's reasonable to expect the set of unknown variables to be small, so I don't think it really matters.

@sarxos
Copy link
Contributor

sarxos commented Jun 29, 2016

Hi @hallvard, I was just stepping by and left few minor comments in the code :)

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.

2 participants