<commit_before>import java.util.ArrayList;
import java.util.List;

public class HashMap<K extends Comparable<K>, V extends Comparable<V>> {

    private class Entry {
        private K key;
        private V value;
        private Entry (K key, V value) {
            this.key = key;
            this.value = value;
        }
    }

    private List<List<Entry>> table;
    private int numEntries;
    private int numBuckets;

    // Input: An object's hash code. Every object has a default Object.hashCode().
    // Output: The hash for internal use. Simple modulus on number of buckets.
    private int hashFunc(int hashCode) {
        return Math.abs(hashCode % numBuckets);
    }

    public HashMap(int size) {
        table = new ArrayList<>(size);
        for (int i = 0; i < size; i++) {
            table.add(new ArrayList<>());
        }
        numEntries = 0;
        numBuckets = size;
    }

    public V get(K key) {
        int idx = hashFunc(key.hashCode());
        List<Entry> chain = table.get(idx);
        if (chain != null) {
            for (Entry entry : chain) {
                if (entry.key.equals(key)) {
                    return entry.value;
                }
            }
        }
        return null;
    }

    public void put(K key, V value) {
        // Check load factor, max 1.
        if ((numEntries + 1) / numBuckets >= 1) {
            numBuckets *= 2;
            HashMap<K, V> hashMap = new HashMap<>(numBuckets);
            for (List<Entry> chain : table) {
                for (Entry entry : chain) {
                    hashMap.put(entry.key, entry.value);
                }
            }
            table = hashMap.table;
        }
        Entry entry = new Entry(key, value);
        int idx = hashFunc(key.hashCode());
        List<Entry> chain = table.get(idx);
        if (chain == null) {
            chain = new ArrayList<>();
            chain.add(entry);
        } else {
            int i;
            for (i = 0; i < chain.size(); i++) {
                if (chain.get(i).key.equals(key)) {
                    chain.set(i, entry);
                    break;
                }
            }
            if (i == chain.size()) {
                chain.add(entry);
            }
        }
        numEntries++;
        table.set(idx, chain);
    }

    public void remove(K key) {
        int idx = hashFunc(key.hashCode());
        List<Entry> chain = table.get(idx);
        if (chain != null) {
            int i;
            for (i = 0; i < chain.size(); i++) {
                if (chain.get(i).key.equals(key)) {
                    break;
                }
            }
            if (i < chain.size()) {
                chain.remove(i);
                numEntries--;
                table.set(idx, chain);
            }
        }
    }<commit_msg>Java hash map fixes.<commit_after>import java.util.ArrayList;
import java.util.List;

public class HashMap<K extends Comparable<K>, V extends Comparable<V>> {

    private class Entry {
        private K key;
        private V value;
        private Entry (K key, V value) {
            this.key = key;
            this.value = value;
        }
    }

    private List<List<Entry>> table;
    private int numEntries;
    private int numBuckets;

    // Input: An object's hash code. Every object has a default Object.hashCode().
    // Output: The hash for internal use. Simple modulus on number of buckets.
    private int hashFunc(int hashCode) {
        return Math.abs(hashCode % numBuckets);
    }

    public HashMap(int size) {
        table = new ArrayList<>(size);
        for (int i = 0; i < size; i++) {
            table.add(new ArrayList<>());
        }
        numEntries = 0;
        numBuckets = size;
    }

    public V get(K key) {
        int idx = hashFunc(key.hashCode());
        List<Entry> chain = table.get(idx);
        if (chain != null) {
            for (Entry entry : chain) {
                if (entry.key.equals(key)) {
                    return entry.value;
                }
            }
        }
        return null;
    }

    public void put(K key, V value) {
        // Check load factor, max 1.
        if ((numEntries + 1) / numBuckets >= 1) {
            numBuckets *= 2;
            HashMap<K, V> hashMap = new HashMap<>(numBuckets);
            for (List<Entry> chain : table) {
                for (Entry entry : chain) {
                    hashMap.put(entry.key, entry.value);
                }
            }
            table = hashMap.table;
        }
        Entry entry = new Entry(key, value);
        int idx = hashFunc(key.hashCode());
        List<Entry> chain = table.get(idx);
        if (chain == null) {
            chain = new ArrayList<>();
            table.set(idx, chain);
        }
        for (int i = 0; i < chain.size(); i++) {
            if (chain.get(i).key.equals(key)) {
                chain.set(i, entry);
                return;
            }
        }
        chain.add(entry);
        numEntries++;
    }

    public void remove(K key) {
        int idx = hashFunc(key.hashCode());
        List<Entry> chain = table.get(idx);
        if (chain != null) {
            for (int i = 0; i < chain.size(); i++) {
                if (chain.get(i).key.equals(key)) {
                    chain.remove(i);
                    numEntries--;
                    return;
                }
            }
        }
    }
{'fraction_non_alphanumeric': 0.12273232136245835, 'fraction_numerical': 0.002961865975564606, 'mean_word_length': 1.348109517601043, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 33, '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': '7020579', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1505, 'n_words': 425}