#

API Docs for: 0.6.0
Show: Inherited Protected Private Deprecated

# File: src/utils/TupleDictionary.js

    module.exports = TupleDictionary;

    /**
     * @class TupleDictionary
     * @constructor
     */
    function TupleDictionary() {

        /**
         * The data storage
         * @property data
         * @type {Object}
         */
        this.data = { keys:[] };
    }

    /**
     * @method get
     * @param  {Number} i
     * @param  {Number} j
     * @return {Number}
     */
    TupleDictionary.prototype.get = function(i, j) {
        if (i > j) {
            // swap
            var temp = j;
            j = i;
            i = temp;
        }
        return this.data[i+'-'+j];
    };

    /**
     * @method set
     * @param  {Number} i
     * @param  {Number} j
     * @param {Number} value
     */
    TupleDictionary.prototype.set = function(i, j, value) {
        if (i > j) {
            var temp = j;
            j = i;
            i = temp;
        }
        var key = i+'-'+j;

        // Check if key already exists
        if(!this.get(i,j)){
            this.data.keys.push(key);
        }

        this.data[key] = value;
    };

    /**
     * @method reset
     */
    TupleDictionary.prototype.reset = function() {
        var data = this.data,
            keys = data.keys;
        while(keys.length > 0){
            var key = keys.pop();
            delete data[key];
        }
    };