js实现的hashtable

AppTui.HashTable = function()
{
    this.__construct();
};

AppTui.HashTable.prototype = {
    __construct: function()
    {
        this._hash = new Object();
    },

    set: function(key, value, rewrite)
    {
        if (rewrite !== false)
        {
            this._hash[key] = value;
        }
        else if (this.get(key) != null)
        {
            this._hash[key] = value;
        }
    },

    get: function(key)
    {
        if (typeof this._hash[key] != "undefined")
        {
            return this._hash[key];
        }
        else
        {
            return null;
        }
    },

    remove: function(key)
    {
        delete this._hash[key];
    }
};

AppTui.HashTable.getInstance = function()
{
    if (!this.__instance__)
    {
        this.__instance__ = new AppTui.HashTable();
    };

    return this.__instance__;
};
原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/2284001.html