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

Use more efficient Set implementation to speed up TextGrid#seedFillOld #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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