<commit_before>
const _ = require('lodash');

class TextDecorationCollection {

    constructor({generateUuid}) {
        this._generateUuid = generateUuid;

        this._map = Object.create(null);
    }

    add({pattern, colour, decorationType}) {
        const id = this._generateUuid();
        const decoration = {pattern, colour, decorationType};
        this._map[id] = decoration;
        return Object.assign({id}, decoration);
    }

    get(id) {
        const value = this._map[id];
        return value ? Object.assign({id}, value) : null;
    }

    remove(id) {
        this._map[id] = null;
    }

    find(predicate) {
        const id = _.findKey(this._map, decoration => decoration && predicate(decoration));
        return id ? Object.assign({id}, this._map[id]) : null;
    }

    toList() {
        return _.reduce(this._map,
            (result, value, key) => value ? [...result, Object.assign({id: key}, value)] : result,
            []
        );
    }

}

module.exports = TextDecorationCollection;
<commit_msg>ref #5 Use native Map. Store id in the decoration object<commit_after>
class TextDecorationCollection {

    constructor({generateUuid}) {
        this._generateUuid = generateUuid;

        this._map = new Map();
    }

    add({pattern, colour, decorationType}) {
        const id = this._generateUuid();
        const decoration = {id, pattern, colour, decorationType};
        this._map.set(id, decoration);
        return decoration;
    }

    get(id) {
        return this._map.get(id);
    }

    remove(id) {
        this._map.delete(id);
    }

    find(predicate) {
        return Array.from(this._map.values())
            .find(decoration => predicate(decoration)) || null;
    }

    toList() {
        return Array.from(this._map.values())
            .reduce((result, decoration) => [...result, decoration], []);
    }

}

module.exports = TextDecorationCollection;

{'fraction_non_alphanumeric': 0.14003123373243104, 'fraction_numerical': 0.0005205622071837585, 'mean_word_length': 2.3838028169014085, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2116179', 'n_tokens_mistral': 587, 'n_tokens_neox': 553, 'n_words': 119}