Commit 1ce46825 authored by Michal Jankowski's avatar Michal Jankowski
Browse files

Memory limiter queue control when deleting empty solutions.

parent b9954f07
...@@ -11,4 +11,6 @@ public interface MemoryLimiter { ...@@ -11,4 +11,6 @@ public interface MemoryLimiter {
void decreaseCount(int count); void decreaseCount(int count);
// Creates node with certain value. // Creates node with certain value.
Node createNode(int value); Node createNode(int value);
// Removes node from queue, does nothing if it's not in queue.
void removeNodeFromQueue(Node node);
} }
\ No newline at end of file
...@@ -89,6 +89,7 @@ public abstract class Tree { ...@@ -89,6 +89,7 @@ public abstract class Tree {
node.getParent().removeChild(node); node.getParent().removeChild(node);
if (node.getParent() != root && node.getParent().getChildrenSize() == 0) { if (node.getParent() != root && node.getParent().getChildrenSize() == 0) {
memoryLimiter.removeNodeFromQueue(node.getParent());
removeLeaf(node.getParent()); removeLeaf(node.getParent());
} }
// There's a corner case in which root can lose its all children. // There's a corner case in which root can lose its all children.
......
...@@ -12,14 +12,17 @@ public class MemoryLimiterImpl implements MemoryLimiter { ...@@ -12,14 +12,17 @@ public class MemoryLimiterImpl implements MemoryLimiter {
this.limit = limit; this.limit = limit;
} }
@Override
public boolean shouldPruneTree() { public boolean shouldPruneTree() {
return count > limit && !accessQueue.empty(); return count > limit && !accessQueue.empty();
} }
@Override
public Node popNodeToPrune() { public Node popNodeToPrune() {
return accessQueue.popFront(); return accessQueue.popFront();
} }
@Override
public void updateRecentlyAccessedNodes(Node startingNode) { public void updateRecentlyAccessedNodes(Node startingNode) {
Node current = startingNode; Node current = startingNode;
...@@ -31,15 +34,22 @@ public class MemoryLimiterImpl implements MemoryLimiter { ...@@ -31,15 +34,22 @@ public class MemoryLimiterImpl implements MemoryLimiter {
} }
} }
@Override
public void decreaseCount(int count) { public void decreaseCount(int count) {
this.count -= count; this.count -= count;
} }
@Override
public Node createNode(int value) { public Node createNode(int value) {
count++; count++;
return new NodeImpl(value); return new NodeImpl(value);
} }
@Override
public void removeNodeFromQueue(Node node) {
accessQueue.removeNodeFromQueue((NodeImpl) node);
}
private void updateRecentlyAccessedNode(Node node) { private void updateRecentlyAccessedNode(Node node) {
accessQueue.pushBack(node); accessQueue.pushBack(node);
} }
......
...@@ -42,7 +42,7 @@ public class Queue { ...@@ -42,7 +42,7 @@ public class Queue {
return front == null; return front == null;
} }
private void removeNodeFromQueue(NodeImpl node) { public void removeNodeFromQueue(NodeImpl node) {
NodeImpl previous = node.getQueueLinker().getPrevious(); NodeImpl previous = node.getQueueLinker().getPrevious();
NodeImpl next = node.getQueueLinker().getNext(); NodeImpl next = node.getQueueLinker().getNext();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment