package main.java.edu.utexas.locke;

import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReferenceArray;

// Sierra
public class LockeDeque {
	
	private int size;
	private volatile Bottom bottom;
	private AtomicReference<Top> top;

	
	public LockeDeque() {
		bottom = new Bottom(new Node(size), size);
		top = new AtomicReference<Top>(new Top(0, bottom.node, 0));
	}
	
	
	public LockeThread popBottom() {

	}



	//Steal from the top
	public LockeThread popTop() {

	}
	
	private static class Node {
		final AtomicReferenceArray<Object> array;
		volatile Node pre, next;

		Node(final int arraySize) {
			array = new AtomicReferenceArray<Object>(arraySize);
		}
	}
	
	private static class Bottom {
		final Node node;
		final int index;

		Bottom (final Node node, final int index) {
			this.node = node;
			this.index = index;
		}
	}

	private static class Top {
		final int tag;
		final Node node;
		final int index;

		Top (final int tag, final Node node, final int index) {
			this.tag = tag;
			this.node = node;
			this.index = index;
		}
	}
	


}
	
@@ -442,14 +442,417 @@
 () %7B
+%0A%09%09
 %0A%0A%09%7D%0A%0A
+%09// Process from thread bottom%0A%09public void pushBottom(final LockeThread thread) %7B%0A%09%09final Bottom local = bottom;%0A%09%09local.node.array.set(local.index, thread); %0A%09%09if (local.index != 0) %7B%0A%09%09%09bottom = new Bottom(local.node, local.index - 1); %0A%09%09%7D else %7B %0A%09%09%09final Node newNode = new Node(size);%0A%09%09%09newNode.next = local.node;%0A%09%09%09local.node.pre = newNode;%0A%09%09%09bottom = new Bottom(newNode, size - 1);%0A%09%09%7D%0A%09%7D
 %0A%0A%09/

Add PushBottom