Improved RecipeMap Backing Storage #3007
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ports 1.12 GTCEu's trie-based data structure, with some change. It should have much faster recipe search times than the current implementation.
Additionally, by its own nature, conflicts and duplicate recipes cannot be stored. All conflicts will have to not be added in the first place as a result. In this scenario, the first conflict will be the "winner" and the others will not be added.
A
Spliterator
is implemented to facilitate potentially performing these searches across multiple threads, but this has not been tested. It is also unlikely multithreading is ever needed here. Concurrent writes to the Trie are not supported, but concurrent reads are (provided that no writes happen concurrently while reading).This PR also fixes a bug in
ItemHolder
'sequals()
implementation, which had an incorrect NBT equality check, and also improves its performance by reducing some extraneous object allocations and removal of unnecessary streams.A brief overview of how this implementation works:
The data structure stores recipes by creating a pathway to them, with one input leading to the next input, and eventually leading to an ending recipe. It is made up of nodes and edges like a regular tree, but operations like tree-shaking and balancing are not performed. Edges in the trie are input ingredients, and nodes are either empty or a recipe. Empty nodes signify that there are more edges to traverse to higher depths. Because nodes cannot be both a recipe and more edges to traverse, conflicting recipes cannot be stored and prevents users from experiencing problems related to it. Recipe lookup walks the tree using the available inputs until a recipe is found.
In the current draft state of this PR, tests are not yet written, and the new data structure is not actively being used for lookup in machines yet. Logging is also disabled due to the massive amount of conflicts currently inside the GT5u repo alone. It should be re-enabled once these conflicts are dealt with.