forked from citiususc/hipster
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pablo.rodriguez.mier
committed
Jun 4, 2013
1 parent
14ce3cc
commit 86b4a7a
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/main/java/es/usc/citius/lab/hipster/collection/HashQueue.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,49 @@ | ||
package es.usc.citius.lab.hipster.collection; | ||
|
||
import java.util.AbstractQueue; | ||
import java.util.Iterator; | ||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
|
||
public class HashQueue<S> extends AbstractQueue<S> { | ||
|
||
private Set<S> elements = new LinkedHashSet<S>(); | ||
private S first = null; | ||
|
||
public boolean offer(S e) { | ||
elements.add(e); | ||
if (first == null) { | ||
first = e; | ||
} | ||
return true; | ||
} | ||
|
||
public S poll() { | ||
// Remove the first element | ||
elements.remove(first); | ||
S out = first; | ||
// Reasign first | ||
first = (elements.isEmpty()) ? null : elements.iterator().next(); | ||
return out; | ||
} | ||
|
||
public S peek() { | ||
return first; | ||
} | ||
|
||
@Override | ||
public Iterator<S> iterator() { | ||
return elements.iterator(); | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return elements.size(); | ||
} | ||
|
||
@Override | ||
public boolean contains(Object o) { | ||
return this.elements.contains(o); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/es/usc/citius/lab/hipster/node/UninformedNode.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,21 @@ | ||
package es.usc.citius.lab.hipster.node; | ||
|
||
public class UninformedNode<S, T extends Comparable<T>> extends AbstractNode<S> implements CostNode<S, T>, Comparable<CostNode<S,T>> { | ||
|
||
private T cost; | ||
|
||
public UninformedNode(Transition<S> transition, CostNode<S,T> previousNode, T cost) { | ||
super(transition, previousNode); | ||
this.cost = cost; | ||
} | ||
|
||
public T getCost() { | ||
return this.cost; | ||
} | ||
|
||
|
||
public int compareTo(CostNode<S, T> o) { | ||
return this.cost.compareTo(o.getCost()); | ||
} | ||
|
||
} |