<commit_before>//
// $Id$

package com.samskivert.util;

import java.util.AbstractMap;
import java.util.AbstractSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * A CountMap maps keys to non-null Integers and provides methods for efficiently adding
 * to the count.
 */
public class CountMap<K> extends AbstractMap<K, Integer>
{
    /**
     * Create a new CountMap backed by a HashMap.
     */
    public CountMap ()
    {
        this(new HashMap<K, CountEntry<K>>());
    }

    /**
     * For subclassing, etc. Not yet public.
     */
    protected CountMap (Map<K, CountEntry<K>> backing)
    {
        if (!backing.isEmpty()) {
            throw new IllegalArgumentException("Map is non-empty");
        }
        _backing = backing;
    }

    /**
     * Add 1 to the count for the specified key.
     */
    public int increment (K key)
    {
        return add(key, 1);
    }

    /**
     * Subtract 1 from the count for the specified key.
     */
    public int decrement (K key)
    {
        return add(key, -1);
    }

    /**
     * Add the specified amount to the count for the specified key.
     */
    public int add (K key, int amount)
    {
        CountEntry<K> entry = _backing.get(key);
        if (entry == null) {
            _backing.put(key, entry = new CountEntry<K>(key, amount));
            return 0;
        }
        return (entry.count += amount);
    }

    /**
     * Get the count for the specified key. If the key is not present, 0 is returned.
     */
    public int getCount (K key)
    {
        CountEntry<K> entry = _backing.get(key);
        return (entry == null) ? 0 : entry.count;
    }

    /**
     * Remove any keys for which the count is currently 0.
     */
    public void compress ()
    {
        for (Iterator<CountEntry<K>> it = _backing.values().iterator(); it.hasNext(); ) {
            if (it.next().count == 0) {
                it.remove();
            }
        }<commit_msg>Correctly return the new count from add().<commit_after>//
// $Id$

package com.samskivert.util;

import java.util.AbstractMap;
import java.util.AbstractSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * A CountMap maps keys to non-null Integers and provides methods for efficiently adding
 * to the count.
 */
public class CountMap<K> extends AbstractMap<K, Integer>
{
    /**
     * Create a new CountMap backed by a HashMap.
     */
    public CountMap ()
    {
        this(new HashMap<K, CountEntry<K>>());
    }

    /**
     * For subclassing, etc. Not yet public.
     */
    protected CountMap (Map<K, CountEntry<K>> backing)
    {
        if (!backing.isEmpty()) {
            throw new IllegalArgumentException("Map is non-empty");
        }
        _backing = backing;
    }

    /**
     * Add 1 to the count for the specified key.
     */
    public int increment (K key)
    {
        return add(key, 1);
    }

    /**
     * Subtract 1 from the count for the specified key.
     */
    public int decrement (K key)
    {
        return add(key, -1);
    }

    /**
     * Add the specified amount to the count for the specified key, return the new count.
     */
    public int add (K key, int amount)
    {
        CountEntry<K> entry = _backing.get(key);
        if (entry == null) {
            _backing.put(key, entry = new CountEntry<K>(key, amount));
            return amount;
        }
        return (entry.count += amount);
    }

    /**
     * Get the count for the specified key. If the key is not present, 0 is returned.
     */
    public int getCount (K key)
    {
        CountEntry<K> entry = _backing.get(key);
        return (entry == null) ? 0 : entry.count;
    }

    /**
     * Remove any keys for which the count is currently 0.
     */
    public void compress ()
    {
        for (Iterator<CountEntry<K>> it = _backing.values().iterator(); it.hasNext(); ) {
            if (it.next().count == 0) {
                it.remove();
            }
        }
{'fraction_non_alphanumeric': 0.12240868706811452, 'fraction_numerical': 0.004195459032576505, 'mean_word_length': 1.9200288184438041, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '7578144', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1212, 'n_words': 390}