-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHash.js
More file actions
104 lines (84 loc) · 2.89 KB
/
Hash.js
File metadata and controls
104 lines (84 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* ************************************************************************
License: MIT
Authors: Lukas Michalski, Benjamin Zeller, Thorsten Schwalb
************************************************************************ */
qx.Class.define("pms.Hash",
{
extend : qx.core.Object,
/******************************************************************************
* CONSTRUCTOR
******************************************************************************/
construct : function()
{
this.base(arguments);
// Create an array to keep the keys for quick access or sorting
this.__keys = [ ];
// The place to keep the values, per key
this.__values = { };
// Create a variable, which has the length of the array
this.__length = 0;
},
members :
{
/******************************************************************************
* FUNCTION: put
******************************************************************************/
put : function(key, value)
{
// Does this key already exist?
if (this.__values[key] === undefined)
{
// Nope. Add its key to the key list
this.__keys.push(key);
// Increase length
this.__length++;
}
// Save the value
this.__values[key] = value;
},
/******************************************************************************
* FUNCTION: get
******************************************************************************/
get : function(key)
{
// Return the value corresponding to the given key
return this.__values[key];
},
/******************************************************************************
* FUNCTION: remove
******************************************************************************/
remove : function(key)
{
// Does this key exist?
if (this.__values[key])
{
// Remove the key from the keys array
qx.lang.Array.remove(this.__keys, key);
// Decrease length
this.__length--;
// Remove the member from the values map
delete this.__values[key];
}
},
/******************************************************************************
* FUNCTION: getSortedKeys
******************************************************************************/
getSortedKeys : function()
{
// Make a copy of the keys so the user doesn't screw with ours
var keys = qx.lang.Array.clone(this.__keys);
// Sort the keys
keys.sort();
// Give 'em what they came for!
return keys;
},
/******************************************************************************
* FUNCTION: getLength
******************************************************************************/
getLength : function()
{
var length = this.__length;
return length;
}
}
});