multikey-map
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -9,4 +9,5 @@ export declare class MultikeyMap<K extends any[], V> { | ||
set(keys: K, value: V): void; | ||
delete(keys: K): boolean; | ||
private getMapValueObject(keys); | ||
} | ||
export default MultikeyMap; |
@@ -20,3 +20,3 @@ "use strict"; | ||
return mapValue ? | ||
['value' in mapValue, mapValue.value] : | ||
[mapValue.valueSet, mapValue.value] : | ||
[false, undefined]; | ||
@@ -31,11 +31,51 @@ }; | ||
if (!mapValue) { | ||
mapValue = { map: createMap(weak) }; | ||
mapValue = { | ||
map: undefined, | ||
valueSet: false, | ||
value: undefined, | ||
}; | ||
map.set(key, mapValue); | ||
} | ||
if (i === keys.length - 1) { | ||
mapValue.value = value; | ||
if (i < keys.length - 1) { | ||
if (mapValue.map) { | ||
map = mapValue.map; | ||
} | ||
else { | ||
map = mapValue.map = createMap(weak); | ||
} | ||
continue; | ||
} | ||
map = mapValue.map; | ||
if (!mapValue.valueSet) { | ||
mapValue.valueSet = true; | ||
} | ||
mapValue.value = value; | ||
} | ||
}; | ||
MultikeyMap.prototype.delete = function (keys) { | ||
var map = this.map; | ||
for (var i = 0; i < keys.length; i++) { | ||
var key = keys[i]; | ||
var mapValue = map.get(key); | ||
if (!mapValue) { | ||
return false; | ||
} | ||
if (i < keys.length - 1) { | ||
if (!mapValue.map) { | ||
return false; | ||
} | ||
map = mapValue.map; | ||
continue; | ||
} | ||
if (mapValue.valueSet) { | ||
mapValue.valueSet = false; | ||
mapValue.value = undefined; | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
// To pass TypeScript checking. | ||
return false; | ||
}; | ||
MultikeyMap.prototype.getMapValueObject = function (keys) { | ||
@@ -49,7 +89,12 @@ var map = this.map; | ||
} | ||
if (i === keys.length - 1) { | ||
return mapValue; | ||
if (i < keys.length - 1) { | ||
if (!mapValue.map) { | ||
return undefined; | ||
} | ||
map = mapValue.map; | ||
continue; | ||
} | ||
map = mapValue.map; | ||
return mapValue; | ||
} | ||
// To pass TypeScript checking. | ||
return undefined; | ||
@@ -56,0 +101,0 @@ }; |
{ | ||
"name": "multikey-map", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Multikey Map", | ||
"scripts": { | ||
"tsc": "tsc", | ||
"tslint": "tslint", | ||
"build": "tsc", | ||
"lint": "tslint --project tsconfig.json --type-check" | ||
"lint": "tslint --project tsconfig.json --type-check", | ||
"test": "ava bld/test" | ||
}, | ||
@@ -17,2 +16,3 @@ "main": "bld/index.js", | ||
"devDependencies": { | ||
"ava": "^0.22.0", | ||
"tslint": "^5.6.0", | ||
@@ -19,0 +19,0 @@ "typescript": "^2.4.2", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8446
117
4