Created
December 13, 2012 02:32
-
-
Save mtmzorro/4273547 to your computer and use it in GitHub Desktop.
-.-
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function HashTable() { | |
var size = 0; | |
var entry = new Object(); | |
this.add = function (key, value) { | |
if (!this.containsKey(key)) { | |
size++; | |
} | |
entry[key] = value; | |
} | |
this.getValue = function (key) { | |
return this.containsKey(key) ? entry[key] : null; | |
} | |
this.remove = function (key) { | |
if (this.containsKey(key) && (delete entry[key])) { | |
size--; | |
} | |
} | |
this.containsKey = function (key) { | |
return (key in entry); | |
} | |
this.containsValue = function (value) { | |
for (var prop in entry) { | |
if (entry[prop] == value) { | |
return true; | |
} | |
} | |
return false; | |
} | |
this.getValues = function () { | |
var values = new Array(); | |
for (var prop in entry) { | |
values.push(entry[prop]); | |
} | |
return values; | |
} | |
this.getKeys = function () { | |
var keys = new Array(); | |
for (var prop in entry) { | |
keys.push(prop); | |
} | |
return keys; | |
} | |
this.setData = function (data) { | |
(typeof data == "object") ? entry = data : window.console && console.log("typeof data is not a object, it's a " + typeof data + ":" + data); | |
} | |
this.getData = function () { | |
return entry; | |
} | |
this.getSize = function () { | |
return size; | |
} | |
this.clear = function () { | |
size = 0; | |
entry = new Object(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment