@typeberry/trie
Advanced tools
Comparing version 0.0.1-6053b62 to 0.0.1-67e835b
@@ -71,2 +71,21 @@ /** | ||
/** Compare the sequence to another one lexicographically. */ | ||
isLessThan(other: BytesBlob): boolean { | ||
const min = Math.min(this.length, other.length); | ||
const thisRaw = this.raw; | ||
const otherRaw = other.raw; | ||
for (let i = 0; i < min; i++) { | ||
if (thisRaw[i] < otherRaw[i]) { | ||
return true; | ||
} | ||
if (thisRaw[i] > otherRaw[i]) { | ||
return false; | ||
} | ||
} | ||
return this.length < other.length; | ||
} | ||
/** Create a new [`BytesBlob'] by converting given UTF-u encoded string into bytes. */ | ||
@@ -493,3 +512,3 @@ static blobFromString(v: string): BytesBlob { | ||
// This has to be benchmarked and re-written to a custom map most likely. | ||
private readonly map = new Map<string, V>(); | ||
private readonly map = new Map<string, [K, V]>(); | ||
@@ -508,3 +527,3 @@ /** Return number of items in the dictionary. */ | ||
get(key: K): V | undefined { | ||
return this.map.get(key.toString()); | ||
return this.map.get(key.toString())?.[1]; | ||
} | ||
@@ -514,3 +533,3 @@ | ||
set(key: K, value: V) { | ||
this.map.set(key.toString(), value); | ||
this.map.set(key.toString(), [key, value]); | ||
} | ||
@@ -522,2 +541,9 @@ | ||
} | ||
/** it allows to use HashDictionary in for-of loop */ | ||
*[Symbol.iterator]() { | ||
for (const value of this.map.values()) { | ||
yield value; | ||
} | ||
} | ||
} | ||
@@ -524,0 +550,0 @@ |
25
index.js
@@ -71,2 +71,17 @@ 'use strict'; | ||
} | ||
/** Compare the sequence to another one lexicographically. */ | ||
isLessThan(other) { | ||
const min = Math.min(this.length, other.length); | ||
const thisRaw = this.raw; | ||
const otherRaw = other.raw; | ||
for (let i = 0; i < min; i++) { | ||
if (thisRaw[i] < otherRaw[i]) { | ||
return true; | ||
} | ||
if (thisRaw[i] > otherRaw[i]) { | ||
return false; | ||
} | ||
} | ||
return this.length < other.length; | ||
} | ||
/** Create a new [`BytesBlob'] by converting given UTF-u encoded string into bytes. */ | ||
@@ -479,7 +494,7 @@ static blobFromString(v) { | ||
get(key) { | ||
return this.map.get(key.toString()); | ||
return this.map.get(key.toString())?.[1]; | ||
} | ||
/** Insert/overwrite the value at given key. */ | ||
set(key, value) { | ||
this.map.set(key.toString(), value); | ||
this.map.set(key.toString(), [key, value]); | ||
} | ||
@@ -490,2 +505,8 @@ /** Remove the key and any value from the dictionary. */ | ||
} | ||
/** it allows to use HashDictionary in for-of loop */ | ||
*[Symbol.iterator]() { | ||
for (const value of this.map.values()) { | ||
yield value; | ||
} | ||
} | ||
} | ||
@@ -492,0 +513,0 @@ |
{ | ||
"name": "@typeberry/trie", | ||
"version": "0.0.1-6053b62", | ||
"version": "0.0.1-67e835b", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "author": "Fluffy Labs", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
48833
1355
0