Skip to content

Commit

Permalink
resolves stathissideris#66 use more efficient Set implementation to s…
Browse files Browse the repository at this point in the history
…peed up TextGrid#seedFillOld
  • Loading branch information
ggrossetie committed Mar 19, 2021
1 parent f2286c4 commit 915853d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ releases/
tests/images/
tests/images-expected/
target/
classes/
21 changes: 16 additions & 5 deletions src/java/org/stathissideris/ascii2image/text/CellSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
package org.stathissideris.ascii2image.text;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

/**
*
Expand All @@ -41,8 +40,20 @@ public class CellSet implements Iterable<TextGrid.Cell> {
public static final int TYPE_HAS_CLOSED_AREA = 3;
public static final int TYPE_UNDETERMINED = 4;

Set<TextGrid.Cell> internalSet = new HashSet<TextGrid.Cell>();

private static final Comparator<TextGrid.Cell> CELL_COMPARATOR = new Comparator<TextGrid.Cell>() {
@Override
public int compare(TextGrid.Cell o1, TextGrid.Cell o2) {
int yResult = Integer.compare(o1.y, o2.y);
if (yResult == 0) {
return Integer.compare(o1.x, o2.x);
} else {
return yResult;
}
}
};

Set<TextGrid.Cell> internalSet = new TreeSet<>(CELL_COMPARATOR);

private int type = TYPE_UNDETERMINED;
private boolean typeIsValid = false;

Expand Down

0 comments on commit 915853d

Please sign in to comment.