Comparing version 0.37.0 to 0.38.0
# Changelog | ||
## 0.38.0 | ||
* Adding `TrieMap.update` (@wholenews). | ||
## 0.37.0 | ||
@@ -4,0 +8,0 @@ |
{ | ||
"name": "mnemonist", | ||
"version": "0.37.0", | ||
"version": "0.38.0", | ||
"description": "Curated collection of data structures for the JavaScript language.", | ||
@@ -81,3 +81,3 @@ "scripts": { | ||
"damerau-levenshtein": "^1.0.6", | ||
"eslint": "^7.3.0", | ||
"eslint": "^7.3.1", | ||
"leven": "^3.1.0", | ||
@@ -84,0 +84,0 @@ "lodash": "^4.17.15", |
@@ -16,2 +16,3 @@ /** | ||
set(prefix: K, value: V): this; | ||
update(prefix: K, updateFunction: (oldValue: V | undefined) => V): this | ||
get(prefix: K): V; | ||
@@ -18,0 +19,0 @@ delete(prefix: K): boolean; |
@@ -70,2 +70,28 @@ /** | ||
/** | ||
* Method used to update the value of the given prefix in the trie. | ||
* | ||
* @param {string|array} prefix - Prefix to follow. | ||
* @param {(oldValue: any | undefined) => any} updateFunction - Update value visitor callback. | ||
* @return {TrieMap} | ||
*/ | ||
TrieMap.prototype.update = function(prefix, updateFunction) { | ||
var node = this.root, | ||
token; | ||
for (var i = 0, l = prefix.length; i < l; i++) { | ||
token = prefix[i]; | ||
node = node[token] || (node[token] = {}); | ||
} | ||
// Do we need to increase size? | ||
if (!(SENTINEL in node)) | ||
this.size++; | ||
node[SENTINEL] = updateFunction(node[SENTINEL]); | ||
return this; | ||
}; | ||
/** | ||
* Method used to return the value sitting at the end of the given prefix or | ||
@@ -72,0 +98,0 @@ * undefined if none exist. |
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
364894
13092