4 var _index = new Hash();
5 _index.set("a", "apple");
6 _index.set("b", "blue");
7 _index.set("c", "coffee");
9 for (var p = _index.first(); p; p = _index.next()) {
10 print(p.key+" is for "+p.value);
14 var Hash
= function() {
21 Hash
.prototype.set
= function(k
, v
) {
24 this._map
["="+k
] = this._vals
.length
;
29 Hash
.prototype.replace
= function(k
, k2
, v
) {
32 var offset
= this._map
["="+k
];
33 this._keys
[offset
] = k2
;
34 if (typeof v
!= "undefined") this._vals
[offset
] = v
;
35 this._map
["="+k2
] = offset
;
36 delete(this._map
["="+k
]);
39 Hash
.prototype.drop
= function(k
) {
41 var offset
= this._map
["="+k
];
42 this._keys
.splice(offset
, 1);
43 this._vals
.splice(offset
, 1);
44 delete(this._map
["="+k
]);
45 for (var p
in this._map
) {
46 if (this._map
[p
] >= offset
) this._map
[p
]--;
48 if (this._cursor
>= offset
&& this._cursor
> 0) this._cursor
--;
52 Hash
.prototype.get
= function(k
) {
54 return this._vals
[this._map
["="+k
]];
58 Hash
.prototype.keys
= function() {
62 Hash
.prototype.hasKey
= function(k
) {
64 return (typeof this._map
["="+k
] != "undefined");
68 Hash
.prototype.values
= function() {
72 Hash
.prototype.reset
= function() {
76 Hash
.prototype.first
= function() {
81 Hash
.prototype.next
= function() {
82 if (this._cursor
++ < this._keys
.length
)
83 return {key
: this._keys
[this._cursor
-1], value
: this._vals
[this._cursor
-1]};