<commit_before>import CustomExceptions.SymbolAlreadyDefinedException;

import java.util.*;

public class HashSymbolTable implements SymbolTable {

    private static class tableEntry {
        private String name;
        private Type type;
        private int depth;
        public tableEntry outOfDeclaration;

        public tableEntry(String name, Type type, int depth) {
            this.name = name;
            this.type = type;
            this.depth = depth;
            outOfDeclaration = null;
        }
    }

    private Map<String, tableEntry> hashTable = new HashMap<String, tableEntry>();
    private Deque<List<tableEntry>> scopeDisplay = new ArrayDeque<List<tableEntry>>();

    public HashSymbolTable() {
        openScope();
    }

    public int getCurrentScopeDepth() {
        return scopeDisplay.size();
    }

    /**
     * Opens a new scope, retaining outer ones
     */
    public void openScope() {
        List<tableEntry> entries = new ArrayList<tableEntry>();
        scopeDisplay.push(entries);
    }

    /**
     * Closes the innermost scope
     */
    public void closeScope() {
        List<tableEntry> entries = scopeDisplay.pop();
        for(tableEntry sym : entries) {
            hashTable.remove(sym.name);

            // Restore outer scope
            tableEntry prev = sym.outOfDeclaration;
            if (prev != null) {
                hashTable.put(prev.name, prev);
            }
        }
    }

    /**
     * Enter the given symbol information into the symbol table. If the given
     * symbol is already present at the current nest level, Throw an exception.
     */
    public void enterSymbol(String id, Type info) throws SymbolAlreadyDefinedException {
        if (declaredLocally(id)) {
            throw new SymbolAlreadyDefinedException();
        }

        tableEntry newSym = new tableEntry(id, info, getCurrentScopeDepth());

        List<tableEntry> entries = scopeDisplay.peek();
        entries.add(newSym);

        tableEntry oldSym = hashTable.get(id);
        if (oldSym != null) {
            hashTable.remove(id);
            newSym.outOfDeclaration = oldSym;
        }
        hashTable.put(id, newSym);
    }

    /**
     * Returns the information associated with the innermost currently valid
     * declaration of the given symbol. If there is no such valid declaration,
     * return null. Do NOT throw any exceptions from this method.
     */
    public Type retrieveSymbol(String id) {
        return hashTable.containsKey(id) ? hashTable.get(id).type : null;
    }<commit_msg>refactoring typo<commit_after>import CustomExceptions.SymbolAlreadyDefinedException;

import java.util.*;

public class HashSymbolTable implements SymbolTable {

    private static class tableEntry {
        private String name;
        private Type type;
        private int depth;
        public tableEntry outerDeclaration;

        public tableEntry(String name, Type type, int depth) {
            this.name = name;
            this.type = type;
            this.depth = depth;
            this.outerDeclaration = null;
        }
    }

    private Map<String, tableEntry> hashTable = new HashMap<String, tableEntry>();
    private Deque<List<tableEntry>> scopeDisplay = new ArrayDeque<List<tableEntry>>();

    public HashSymbolTable() {
        openScope();
    }

    public int getCurrentScopeDepth() {
        return scopeDisplay.size();
    }

    /**
     * Opens a new scope, retaining outer ones
     */
    public void openScope() {
        List<tableEntry> entries = new ArrayList<tableEntry>();
        scopeDisplay.push(entries);
    }

    /**
     * Closes the innermost scope
     */
    public void closeScope() {
        List<tableEntry> entries = scopeDisplay.pop();
        for(tableEntry sym : entries) {
            hashTable.remove(sym.name);

            // Restore outer scope
            tableEntry prev = sym.outerDeclaration;
            if (prev != null) {
                hashTable.put(prev.name, prev);
            }
        }
    }

    /**
     * Enter the given symbol information into the symbol table. If the given
     * symbol is already present at the current nest level, Throw an exception.
     */
    public void enterSymbol(String id, Type info) throws SymbolAlreadyDefinedException {
        if (declaredLocally(id)) {
            throw new SymbolAlreadyDefinedException();
        }

        tableEntry newSym = new tableEntry(id, info, getCurrentScopeDepth());

        List<tableEntry> entries = scopeDisplay.peek();
        entries.add(newSym);

        tableEntry oldSym = hashTable.get(id);
        if (oldSym != null) {
            hashTable.remove(id);
            newSym.outerDeclaration = oldSym;
        }
        hashTable.put(id, newSym);
    }

    /**
     * Returns the information associated with the innermost currently valid
     * declaration of the given symbol. If there is no such valid declaration,
     * return null. Do NOT throw any exceptions from this method.
     */
    public Type retrieveSymbol(String id) {
        return hashTable.containsKey(id) ? hashTable.get(id).type : null;
    }
{'fraction_non_alphanumeric': 0.08947368421052632, 'fraction_numerical': 0.0, 'mean_word_length': 2.2536461636017755, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '5917987', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1301, 'n_words': 395}