1 |
|
2 | "use strict";
|
3 |
|
4 | var utils = require("./utils.js");
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | function FMap(eq) {
|
18 | this.eq = eq || utils.isEqual;
|
19 | this.data = [];
|
20 | }
|
21 |
|
22 | FMap.prototype.contains = function FMapContains(key) {
|
23 | for (var i = 0; i < this.data.length; i++) {
|
24 | if (this.eq(this.data[i][0], key)) {
|
25 | return true;
|
26 | }
|
27 | }
|
28 |
|
29 | return false;
|
30 | };
|
31 |
|
32 | FMap.prototype.insert = function FMapInsert(key, value) {
|
33 | for (var i = 0; i < this.data.length; i++) {
|
34 | if (this.eq(this.data[i][0], key)) {
|
35 | this.data[i] = [key, value];
|
36 | return;
|
37 | }
|
38 | }
|
39 |
|
40 | this.data.push([key, value]);
|
41 | };
|
42 |
|
43 | FMap.prototype.get = function FMapGet(key) {
|
44 | for (var i = 0; i < this.data.length; i++) {
|
45 | if (this.eq(this.data[i][0], key)) {
|
46 | return this.data[i][1];
|
47 | }
|
48 | }
|
49 | };
|
50 |
|
51 | module.exports = FMap;
|