Skip to content

Commit

Permalink
Use LinkedHashSet for Breadth First Search. (#2697)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomprince authored Jan 10, 2025
1 parent cfaa1a8 commit 9ca23ca
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class BreadthFirstBlockSearch {

public static Set<BlockPos> search(Predicate<BlockPos> value, BlockPos start, int limit) {
Set<BlockPos> alreadyVisited = new HashSet<>();
Set<BlockPos> valid = new HashSet<>();
Set<BlockPos> valid = new LinkedHashSet<>();
int iteration = 0;

Queue<BlockPos> queue = new ArrayDeque<>();
Expand Down Expand Up @@ -58,7 +58,7 @@ public static <T extends BlockEntity> Set<T> conditionalBlockEntitySearch(Class<
var level = start.getLevel();
if (level == null) return Set.of();

var passed = new HashSet<T>();
var passed = new LinkedHashSet<T>();
var queue = new ObjectArrayFIFOQueue<Triple<T, T, Direction>>(16);
queue.enqueue(new ImmutableTriple<>(null, start, null));

Expand Down Expand Up @@ -87,7 +87,7 @@ public static <T extends BlockEntity> Set<T> conditionalBlockEntitySearch(Class<

public static Set<BlockPos> conditionalBlockPosSearch(BlockPos start, BiPredicate<BlockPos, BlockPos> condition,
int blockLimit, int iterationLimit) {
var passed = new HashSet<BlockPos>();
var passed = new LinkedHashSet<BlockPos>();
var queue = new ObjectArrayFIFOQueue<Tuple<BlockPos, BlockPos>>(16);
queue.enqueue(new Tuple<>(null, start));

Expand Down

0 comments on commit 9ca23ca

Please sign in to comment.