Skip to content

reduce the retained memory by deducting the minimal character#61

Open
donnerpeter wants to merge 1 commit intohankcs:masterfrom
donnerpeter:fix
Open

reduce the retained memory by deducting the minimal character#61
donnerpeter wants to merge 1 commit intohankcs:masterfrom
donnerpeter:fix

Conversation

@donnerpeter
Copy link
Copy Markdown

also add a constructor with a Map to avoid single-line trie creation and bump the Java version to one supported by modern JDKs

also add a constructor with a Map to avoid single-line trie creation
and bump the Java version to one supported by modern JDKs
Copy link
Copy Markdown
Owner

@hankcs hankcs left a comment

Choose a reason for hiding this comment

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

Thank you for the PR, nice improvement!

I left some comments in the review. Also, the save and load need to be updated to handle minChar.

Comment thread pom.xml

<properties>
<java.version>1.6</java.version>
<java.version>9</java.version>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Do we have any Java 9 features required by this PR, other than the test code? Some users are still running Java 6.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

No, only tests. I mostly increased the version because my current JDK refused to produce 1.6 bytecode. Are you sure such users still exist? Java 6 reached end of life quite some time ago.

minChar = (char) Math.min(minChar, keyword.charAt(j));
}
}
if (minChar != Character.MAX_VALUE) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I'm considering an edge case where all keywords are Character.MAX_VALUE. Maybe we should start with sth like:

int minChar = Character.MAX_VALUE + 1;

@donnerpeter
Copy link
Copy Markdown
Author

Also, the save and load need to be updated to handle minChar.

A good catch, thanks! That's where it can get complicated. Should previously saved versions be loadable by the new one? If yes, I'm considering two approaches:

  1. An easier, but more hacky one: write minChar to the end and catch EOFException when reading, then assuming it's 0.
  2. Save and load arrays as now, adding and recalculating minChar during save/load.

What would you prefer?

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