/**
 * A simple map implementation in JavaScript.  This map class generates a random key for 
 * objects and the stores that key in the object itself, which is then used later when
 * looking up the value for an object in the map.  Because of this, separately 
 * instantiated objects will not map to the same value in the map.  In this regard, this 
 * map class doesn't behave like maps in other languages such as Java or Ruby, but it
 * still might be useful for some scenarios.
 *
 * Copyright Chris TenHarmsel, 2009
 * chris@tenharmsel.com
 * http://www.staticmethod.net
 */

var JsMap = function() {
    var _internalMap = {};

    // Private function for getting the key for an object
    function getKey(obj) {
        if(obj.__jsKey == null) {
            obj.__jsKey = generateKey();
        }
        return obj.__jsKey;
    };

    // Generates a "key" (string really)
    function generateKey() {
        var d = new Date();
        var t = d.getTime();
        var part = t * Math.random();
        t = part * t;
        t = t % 9876103;
        return "" + t;
    };

    this._put = function(key, value) {
        var objKey = getKey(key);
        _internalMap[objKey] = value;
    };

    this._get = function(key) {
        var objKey = getKey(key);
        return _internalMap[objKey];
    };

    this._remove = function(key) {
        var objKey = getKey(key);
        if( _internalMap[objKey] != null) {
            delete(_internalMap[objKey]);
        }
    };

    this.size = function() {
        count = 0;
        for(var i in _internalMap) {
            count++;
        }
        return count;
    };

};

JsMap.prototype.put = function(key, value) {
    this._put(key, value);
};

JsMap.prototype.get = function(key) {
    return this._get(key);
};

JsMap.prototype.remove = function(key) {
    this._remove(key);
};