-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add tuple map class #139
add tuple map class #139
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @bmschmidt and the rest of your teammates on Graphite |
3f1e0d5
to
bc0cfea
Compare
290e0fe
to
dd9bc11
Compare
Merge activity
|
bc0cfea
to
552887a
Compare
dd9bc11
to
cd93751
Compare
cd93751
to
48c5da6
Compare
@@ -82,3 +82,69 @@ function createDictionaryWithVector( | |||
|
|||
return returnval; | |||
} | |||
|
|||
export class TupleMap<K = Object, V = Object> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using objects as keys in TupleMap
can lead to unexpected behavior because object references are compared, not their content. Consider using a serialization method for object keys to ensure consistent behavior.
private map: Map<K, TupleMap<K, V>> = new Map(); | ||
private value?: V; | ||
|
||
set(keys: K[], value: V): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic to traverse the map is repeated in set
, get
, has
, and delete
methods. Consider refactoring this into a separate method to adhere to the DRY principle.
We often have to use a tuple of things as indexes in deepscatter. This creates a class that allows accessing things by string (or object) indexes so that you can do things like:
Even though the objects don't match.
feat: add
TupleMap
class for tuple-based indexingSummary:
Introduces
TupleMap
class for efficient tuple-based indexing with string or object keys, supporting various methods and cleaning up empty maps.Key points:
TupleMap
class insrc/utilityFunctions.ts
for tuple-based indexing.set
,get
,has
, anddelete
methods.a.set(["foo", "bar"], 2); a.get(["foo", "bar"])
.Generated with ❤️ by ellipsis.dev