Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved performance for liveness calculation in LocalMerger
- using immutable collections to share data between nodes in the graph - better strategy for calculating fixed point
- Loading branch information
Showing
3 changed files
with
107 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
de.peeeq.wurstscript/src/main/java/de/peeeq/datastructures/Worklist.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package de.peeeq.datastructures; | ||
|
||
import java.util.ArrayDeque; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
|
||
/** | ||
* A queue with efficient lookup using a hashset. | ||
* <p> | ||
* No element is added to the queue more than once. | ||
*/ | ||
public class Worklist<T> { | ||
private ArrayDeque<T> queue = new ArrayDeque<>(); | ||
private HashSet<T> set = new HashSet<>(); | ||
|
||
public Worklist() { | ||
} | ||
|
||
public Worklist(Iterable<? extends T> nodes) { | ||
for (T node : nodes) { | ||
addLast(node); | ||
} | ||
} | ||
|
||
public boolean isEmpty() { | ||
return queue.isEmpty(); | ||
} | ||
|
||
|
||
public void addFirst(T node) { | ||
if (set.add(node)) { | ||
queue.addFirst(node); | ||
} | ||
} | ||
|
||
public void addLast(T node) { | ||
if (set.add(node)) { | ||
queue.addLast(node); | ||
} | ||
} | ||
|
||
public T poll() { | ||
T result = queue.poll(); | ||
if (result != null) { | ||
set.remove(result); | ||
} | ||
return result; | ||
} | ||
|
||
public int size() { | ||
return queue.size(); | ||
} | ||
|
||
public void addAll(Collection<? extends T> elems) { | ||
for (T elem : elems) { | ||
addLast(elem); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters