1function hashFnv32a(str, asString, seed) {
2 /*jshint bitwise:false */
3 var i, l,
4 hval = (seed === undefined) ? 0x811c9dc5 : seed;
5
6 for (i = 0, l = str.length; i < l; i++) {
7 hval ^= str.charCodeAt(i);
8 hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
9 }
10 if( asString ){
11 // Convert to 8 digit hex string
12 return ("0000000" + (hval >>> 0).toString(16)).substr(-8);
13 }
14 return hval >>> 0;
15}
1function HashTable(obj)
2{
3 this.length = 0;
4 this.items = {};
5 for (var p in obj) {
6 if (obj.hasOwnProperty(p)) {
7 this.items[p] = obj[p];
8 this.length++;
9 }
10 }
11
12 this.setItem = function(key, value)
13 {
14 var previous = undefined;
15 if (this.hasItem(key)) {
16 previous = this.items[key];
17 return previous;
18 }
19 else {
20 this.length++;
21 }
22 this.items[key] = value;
23 return previous;
24 }
25
26 this.getItem = function(key) {
27 return this.hasItem(key) ? this.items[key] : undefined;
28 }
29
30 this.hasItem = function(key)
31 {
32 return this.items.hasOwnProperty(key);
33 }
34
35 this.removeItem = function(key)
36 {
37 if (this.hasItem(key)) {
38 previous = this.items[key];
39 this.length--;
40 delete this.items[key];
41 return previous;
42 }
43 else {
44 return undefined;
45 }
46 }
47
48 this.keys = function()
49 {
50 var keys = [];
51 for (var k in this.items) {
52 if (this.hasItem(k)) {
53 keys.push(k);
54 }
55 }
56 return keys;
57 }
58
59 this.values = function()
60 {
61 var values = [];
62 for (var k in this.items) {
63 if (this.hasItem(k)) {
64 values.push(this.items[k]);
65 }
66 }
67 return values;
68 }
69
70 this.each = function(fn) {
71 for (var k in this.items) {
72 if (this.hasItem(k)) {
73 fn(k, this.items[k]);
74 }
75 }
76 }
77
78 this.clear = function()
79 {
80 this.items = {}
81 this.length = 0;
82 }
83}
84
1var h = new Object(); // or just {}
2h['one'] = 1;
3h['two'] = 2;
4h['three'] = 3;
5
6// show the values stored
7for (var k in h) {
8 // use hasOwnProperty to filter out keys from the Object.prototype
9 if (h.hasOwnProperty(k)) {
10 alert('key is: ' + k + ', value is: ' + h[k]);
11 }
12}
13