<commit_before>/*
* cachingStore
* author: ruleechen
* contact: <EMAIL>
* create date: 2014.7.16
*/

'use strict';

var events = require('events'),
    utils = require('zoo-utils');

var cachingStore = module.exports = function() {
    this._data = {};
    this.events = new events.EventEmitter();
};

cachingStore.prototype = {

    _data: null, events: null,

    constructor: cachingStore, className: 'cachingStore',

    get: function(region, key) {
        region = utils.formalStr(region);
        key = utils.formalStr(key);
        //
        if (arguments.length === 0) {
            return this._data;
        } else {
            var r = this._data[region];
            if (arguments.length === 1) {
                return r;
            } else {
                return r ? r[key] : r;
            }
        }
    },

    set: function(region, key, val) {
        region = utils.formalStr(region);
        key = utils.formalStr(key);
        //
        if (arguments.length === 2) {
            this._data[region] = key;
        }
        if (arguments.length === 3) {
            var r = this._data[region];
            if (!r) { r = this._data[region] = {}; }
            r[key] = val;
        }
    },

    remove: function(region, key) {
        region = utils.formalStr(region);
        key = utils.formalStr(key);
        //
        if (arguments.length === 1) {
            return delete this._data[region];
        } else {
            var r = this._data[region];
            if (r) { return delete r[key]; }
            return false;
        }
    },

    exists: function(region, key) {
        region = utils.formalStr(region);
        key = utils.formalStr(key);
        //
        if (arguments.length === 1) {
            return (region in this._data);
        } else {
            var r = this._data[region];
            return (r && key in r);
        }
    },

    clear: function(region) {
        region = utils.formalStr(region);
        //
        if (arguments.length === 0) {
            this._data = {};
            return true;
        } else {
            return delete this._data[region];
        }
    }
};<commit_msg>better implementation<commit_after>/*
* cachingStore
* author: ruleechen
* contact: <EMAIL>
* create date: 2014.7.16
*/

'use strict';

var events = require('events'),
    utils = require('zoo-utils');

var cachingStore = module.exports = function() {
    this._data = {};
    this.events = new events.EventEmitter();
};

cachingStore.prototype = {

    _data: null, events: null,

    constructor: cachingStore, className: 'cachingStore',

    get: function(regionName, key) {
        regionName = utils.formalStr(regionName);
        var region = this._data[regionName];
        if (key === undefined) {
            return region;
        } else {
            key = utils.formalStr(key);
            return region ? region[key] : region;
        }
    },

    set: function(regionName, key, val) {
        regionName = utils.formalStr(regionName);
        var region = this._data[regionName];
        if (!region) { region = this._data[regionName] = {}; }
        region[utils.formalStr(key)] = val;
    },

    remove: function(regionName, key) {
        regionName = utils.formalStr(regionName);
        if (key === undefined) {
            return delete this._data[regionName];
        } else {
            var region = this._data[regionName];
            if (region) {
                key = utils.formalStr(key);
                return delete region[key];
            } else {
                return false;
            }
        }
    },

    exists: function(regionName, key) {
        regionName = utils.formalStr(regionName);
        if (key === undefined) {
            return (regionName in this._data);
        } else {
            var region = this._data[regionName];
            key = utils.formalStr(key);
            return (region && key in region);
        }
    },

    clear: function(regionName) {
        if (regionName === undefined) {
            this._data = {};
            return true;
        } else {
            regionName = utils.formalStr(regionName);
            return delete this._data[regionName];
        }
    }
};
{'fraction_non_alphanumeric': 0.13328581610833928, 'fraction_numerical': 0.004989308624376337, 'mean_word_length': 1.705655526992288, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5588478', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1199, 'n_words': 276}