Skip to content

Commit

Permalink
Revert "Optimize ingredient positions index"
Browse files Browse the repository at this point in the history
This reverts commit 61b7372.

Closes CyclopsMC/IntegratedTerminals#134
  • Loading branch information
rubensworks committed Oct 29, 2024
1 parent 18b455b commit bdef44d
Showing 1 changed file with 1 addition and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.cyclops.cyclopscore.ingredient.collection.IIngredientMapMutable;
import org.cyclops.cyclopscore.ingredient.collection.IngredientCollectionHelpers;
import org.cyclops.cyclopscore.ingredient.collection.IngredientHashMap;
import org.cyclops.cyclopscore.ingredient.collection.IngredientMapSingleClassified;
import org.cyclops.integrateddynamics.api.ingredient.IIngredientPositionsIndex;
import org.cyclops.integrateddynamics.api.part.PartPos;
import org.cyclops.integrateddynamics.api.part.PrioritizedPartPos;
Expand Down Expand Up @@ -67,7 +66,7 @@ public Iterator<PartPos> getPositions(T instance, M matchFlags) {
public void addPosition(T instance, PrioritizedPartPos pos) {
IIngredientMapMutable<T, M, ObjectOpenHashSet<PartPos>> positionsMap = this.prioritizedPositionsMap.get(getInternalPriority(pos));
if (positionsMap == null) {
positionsMap = createCollapsedMap(getComponent());
positionsMap = new IngredientHashMap<>(getComponent());
this.prioritizedPositionsMap.put(getInternalPriority(pos), positionsMap);
}

Expand All @@ -81,17 +80,6 @@ public void addPosition(T instance, PrioritizedPartPos pos) {
set.add(pos.getPartPos());
}

// If this would ever be needed in other places as well, let's move this to IngredientCollectionHelpers
protected static <T, M> IIngredientMapMutable<T, M, ObjectOpenHashSet<PartPos>> createCollapsedMap(IngredientComponent<T, M> ingredientComponent) {
if (ingredientComponent.getCategoryTypes().size() == 1) {
return new IngredientHashMap<>(ingredientComponent);
}
return new IngredientMapSingleClassified<>(
ingredientComponent,
() -> new IngredientHashMap<>(ingredientComponent),
ingredientComponent.getCategoryTypes().get(0));
}

@Override
public void removePosition(T instance, PrioritizedPartPos pos) {
IIngredientMapMutable<T, M, ObjectOpenHashSet<PartPos>> positionsMap = this.prioritizedPositionsMap.get(getInternalPriority(pos));
Expand Down

0 comments on commit bdef44d

Please sign in to comment.