Skip to content

Commit

Permalink
HashQueue and UninformedNode added.
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo.rodriguez.mier committed Jun 4, 2013
1 parent 14ce3cc commit 86b4a7a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/main/java/es/usc/citius/lab/hipster/collection/HashQueue.java
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 src/main/java/es/usc/citius/lab/hipster/node/UninformedNode.java
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());
}

}

0 comments on commit 86b4a7a

Please sign in to comment.