现在的位置: 首页 > 综合 > 正文

js实现的hashtable

2012年08月12日 ⁄ 综合 ⁄ 共 706字 ⁄ 字号 评论关闭
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__;
};

抱歉!评论已关闭.