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

Optimize list of material filters #1464

Merged
merged 1 commit into from
Dec 28, 2024
Merged

Optimize list of material filters #1464

merged 1 commit into from
Dec 28, 2024

Conversation

Pablete1234
Copy link
Member

Purely an internal change, i optimizes things like this:

(yes, this is a real filter used in a real map)

<any>
  <material>stone:6</material>
  <material>stone button</material>
  <material>smooth brick</material>
  <material>smooth brick:2</material>
  <material>cobblestone</material>
  <material>mossy cobblestone</material>
  <material>cobblestone stairs</material>
  <material>cobble wall</material>
  <material>cobble wall:1</material>
  <material>double step</material>
  <material>double step:3</material>
  <material>double step:4</material>
  <material>double step:5</material>
  <material>double step:8</material>
  <material>step</material>
  <material>step:3</material>
  <material>step:5</material>
  <material>stone plate</material>
  <material>stained glass</material>
  <material>iron fence</material>
  <material>vine</material>
  <material>smooth stairs</material>
  <material>water lily</material>
  <material>wall banner</material>
  <material>trap door</material>
  <material>long grass</material>
  <material>red rose</material>
  <material>double plant</material>   
  <material>red mushroom</material>
  <material>brown mushroom</material>
  <material>diamond block</material>
  <material>gold block</material>
  <material>gold ore</material>
  <material>long grass</material>
  <material>long grass:2</material>
  <material>red rose</material>
  <material>red rose:1</material>
  <material>red rose:2</material>
  <material>red rose:3</material>
  <material>red rose:4</material>
  <material>red rose:5</material>
  <material>red rose:6</material>
  <material>red rose:7</material>
  <material>red rose:8</material>
  <material>lapis ore</material>
  <material>redstone ore</material>
  <material>leaves:2</material>
  <material>leaves:3</material>
  <material>leaves:4</material>
  <material>leaves</material>
  <material>leaves 2</material>
  <material>leaves:1</material>
</any>

By turning this into just one material filter with a composite matcher having a multiple-material-matcher, and an exact material matcher:

MaterialFilter{pattern=CompoundMaterialMatcher{children=[

MultipleMaterialMatcher{materials=[COBBLESTONE, GOLD_ORE, LEAVES, LAPIS_ORE, LONG_GRASS, RED_ROSE, BROWN_MUSHROOM, RED_MUSHROOM, GOLD_BLOCK, DOUBLE_STEP, STEP, MOSSY_COBBLESTONE, DIAMOND_BLOCK, COBBLESTONE_STAIRS, STONE_PLATE, REDSTONE_ORE, STONE_BUTTON, STAINED_GLASS, TRAP_DOOR, SMOOTH_BRICK, IRON_FENCE, VINE, SMOOTH_STAIRS, WATER_LILY, COBBLE_WALL, LEAVES_2, DOUBLE_PLANT, WALL_BANNER]}, 

ExactMaterialMatcher{material=STONE, data=6}
]}}

What this means is it will be solved in one set-check against materials O(1), and then a follow-up check for the exact stone:6, instead of having to perform up to 50 checks

@Pablete1234 Pablete1234 merged commit 5803438 into dev Dec 28, 2024
2 checks passed
@Pablete1234 Pablete1234 deleted the optimize-any-materials branch December 28, 2024 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants