Map set implemented by javascript and javascriptmap set
A few days ago, the project wanted to use a map set of the same things. It took a while to get the object. Today, I am idle to implement it.
Don't laugh
Code
Var Map = function () {/************ basic variable ***************/var hashmap = {}; var keys = []; var vals = []; var entrys = []; var size = 0; var index = {}; var Entry = function (key, value) {var entryKey = key; var entryValue = value; this. getKey = function () {return entryKey;}; this. getValue = function () {return entryValue ;};};. clear = function (key) {hashm Ap [key] = undefined; var I = index [key]; entrys. splice (I, 1); vals. splice (I, 1); keys. splice (I, 1); size --;}; this. entrySet = function () {return entrys;}; this. get = function (key) {return hashmap [key] ;}; this. isEmpty = function () {if (hashmap) return true; return false ;}; this. keySet = function () {return keys;}; this. put = function (key, value) {if (! This. get (key) {entrys. push (new Entry (key, value); keys. push (key); vals. push (value); index [key] = size; size ++;} else {var I = index [key]; entrys [I] = new Entry (key, value ); vals [I] = value;} hashmap [key] = value;}; this. size = function () {return size ;}; this. values = function () {return vals ;};};. prototype = {containsKey: function (key) {if (this. get (key) return true; return false ;}, putAll: function (set) {for (var e in set) {if (set [e]) {this. put (e, set [e]) ;}}, remove: function (key) {var v = this. get (key); this. clear (key); return v ;}}; var h = new Map (); h. put ('A', 10); h. put ('B', 11); h. put ('C', 3); h. put ('D', 5); console.info (h. size (); h. clear ('A'); console.info (h. containsKey ('A'); console.info (h. containsKey ('B'); console.info (h. size (); console. log (h. entrySet (); console. log (h. keySet (); console. log (h. values (); for (var I in h. entrySet () {var obj = h. entrySet () [I]; console. log (obj. getKey () + ":" + obj. getValue ());}
The above is all the content of this article. I hope you will like it.