<commit_before>package org.suporma.gears;

import java.util.AbstractCollection;
import java.util.Deque;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * This class is intended to track an ordering of objects. The expectation is that each object will
 * appear no more than once.
 */
public class Ordering<T> extends AbstractCollection<T> implements Deque<T> {
    private class Node {
        final T val;
        Node prev, next;
        
        public Node(T val) {
            this.val = val;
            this.prev = null;
            this.next = null;
        }
    }
    
    private final Map<T, Node> nodeMap;
    private final Node first, last;
    
    public Ordering() {
        this.nodeMap = new HashMap<>();
        this.first = new Node(null);
        this.last = new Node(null);
        first.next = last;
        last.prev = first;
    }
    
    private void put(T val, Node precedent) {
        Node node = nodeMap.get(val);
        boolean isNewNode = false;
        if (node == null) {
            isNewNode = true;
            node = new Node(val);
        }
        if (node.prev != null) {
            Node prev = node.prev;
            Node next = node.next;
            prev.next = next;
            next.prev = prev;
        }
        Node next = precedent.next;
        node.prev = precedent;
        node.next = next;
        precedent.next = node;
        next.prev = node;
        if (isNewNode) {
            nodeMap.put(val, node);
        }
    }
    
    public boolean putAfter(T val, T precedent) {
        Node precedentNode = nodeMap.get(precedent);
        if (precedentNode == null) return false;
        put(val, precedentNode);
        return true;
    }
    
    public boolean putBefore(T val, T follower) {
        Node followerNode = nodeMap.get(follower);
        if (followerNode == null) return false;
        put(val, followerNode.prev);
        return true;
    }
    
    public boolean swap(T val1, T val2) {
        // TODO
        return false;
    }

    @Override
    public void addFirst(T e) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void addLast(T e) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public boolean offerFirst(T e) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean offerLast(T e) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public T removeFirst() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public T removeLast() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public T pollFirst() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public T pollLast() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public T getFirst() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public T getLast() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public T peekFirst() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public T peekLast() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public boolean removeFirstOccurrence(Object o) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean removeLastOccurrence(Object o) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean offer(T e) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public T remove() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public T poll() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public T element() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public T peek() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void push(T e) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public T pop() {
        // TODO Auto-generated method stub<commit_msg>Filling in some basic functions<commit_after>package org.suporma.gears;

import java.util.AbstractCollection;
import java.util.Deque;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;

/**
 * This class is intended to track an ordering of objects. The expectation is that each object will
 * appear no more than once.
 */
public class Ordering<T> extends AbstractCollection<T> implements Deque<T> {
    private class Node {
        final T val;
        Node prev, next;
        
        public Node(T val) {
            this.val = val;
            this.prev = null;
            this.next = null;
        }
    }
    
    private final Map<T, Node> nodeMap;
    private final Node front, back;
    
    public Ordering() {
        this.nodeMap = new HashMap<>();
        this.front = new Node(null);
        this.back = new Node(null);
        front.next = back;
        back.prev = front;
    }
    
    private void put(T val, Node precedent) {
        Node node = nodeMap.get(val);
        boolean isNewNode = false;
        if (node == null) {
            isNewNode = true;
            node = new Node(val);
        }
        if (node.prev != null) {
            Node prev = node.prev;
            Node next = node.next;
            prev.next = next;
            next.prev = prev;
        }
        Node next = precedent.next;
        node.prev = precedent;
        node.next = next;
        precedent.next = node;
        next.prev = node;
        if (isNewNode) {
            nodeMap.put(val, node);
        }
    }
    
    public boolean putAfter(T val, T precedent) {
        Node precedentNode = nodeMap.get(precedent);
        if (precedentNode == null) return false;
        put(val, precedentNode);
        return true;
    }
    
    public boolean putBefore(T val, T follower) {
        Node followerNode = nodeMap.get(follower);
        if (followerNode == null) return false;
        put(val, followerNode.prev);
        return true;
    }
    
    public boolean swap(T val1, T val2) {
        // TODO
        return false;
    }

    @Override
    public void addFirst(T e) {
        put(e, front);
    }

    @Override
    public void addLast(T e) {
        put(e, back.prev);
    }

    @Override
    public boolean offerFirst(T e) {
        addFirst(e);
        return true;
    }

    @Override
    public boolean offerLast(T e) {
        addLast(e);
        return true;
    }
    
    private T removeNode(Node node) {
        Node prev = node.prev;
        Node next = node.next;
        prev.next = next;
        next.prev = prev;
        T val = node.val;
        nodeMap.remove(val);
        return val;
    }

    @Override
    public T removeFirst() {
        if (isEmpty()) throw new NoSuchElementException();
        return removeNode(front.next);
    }

    @Override
    public T removeLast() {
        if (isEmpty()) throw new NoSuchElementException();
        return removeNode(back.prev);
    }

    @Override
    public T pollFirst() {
        if (isEmpty()) return null;
        return removeNode(front.next);
    }

    @Override
    public T pollLast() {
        if (isEmpty()) return null;
        return removeNode(back.prev);
    }

    @Override
    public T getFirst() {
        if (isEmpty()) throw new NoSuchElementException();
        return front.next.val;
    }

    @Override
    public T getLast() {
        if (isEmpty()) throw new NoSuchElementException();
        return back.prev.val;
    }

    @Override
    public T peekFirst() {
        if (isEmpty()) return null;
        return front.next.val;
    }

    @Override
    public T peekLast() {
        if (isEmpty()) return null;
        return back.prev.val;
    }

    @Override
    public boolean removeFirstOccurrence(Object o) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean removeLastOccurrence(Object o) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean offer(T e) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public T remove() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public T poll() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public T element() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public T peek() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void push(T e) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public T pop() {
        // TODO Auto-generated method stub
{'fraction_non_alphanumeric': 0.09281502511465385, 'fraction_numerical': 0.00043677658877484165, 'mean_word_length': 1.6827768014059754, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '969111', 'n_tokens_mistral': 2630, 'n_tokens_neox': 2547, 'n_words': 793}