Skip to content
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

Merged
merged 1 commit into from
Sep 20, 2024
Merged

add tuple map class #139

merged 1 commit into from
Sep 20, 2024

Conversation

bmschmidt
Copy link
Collaborator

@bmschmidt bmschmidt commented Sep 9, 2024

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:

const a = new TupleMap();
a.set(["foo", "bar"], 2)
a.get(["foo", "bar"])
// == 3

Even though the objects don't match.


🚀 This description was created by 48c5da6

feat: add TupleMap class for tuple-based indexing

Summary:

Introduces TupleMap class for efficient tuple-based indexing with string or object keys, supporting various methods and cleaning up empty maps.

Key points:

  • Introduces TupleMap class in src/utilityFunctions.ts for tuple-based indexing.
  • Supports set, get, has, and delete methods.
  • Allows string or object keys in tuples.
  • Handles non-matching object keys gracefully.
  • Cleans up empty nested maps after deletion.
  • Example usage: a.set(["foo", "bar"], 2); a.get(["foo", "bar"]).

Generated with ❤️ by ellipsis.dev

Copy link
Collaborator Author

bmschmidt commented Sep 9, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @bmschmidt and the rest of your teammates on Graphite Graphite

@bmschmidt bmschmidt force-pushed the remove_deferred_functions_queue branch from 3f1e0d5 to bc0cfea Compare September 19, 2024 18:59
@bmschmidt bmschmidt force-pushed the 09-07-add_tuplemap_class branch from 290e0fe to dd9bc11 Compare September 19, 2024 19:00
Copy link
Collaborator Author

bmschmidt commented Sep 19, 2024

Merge activity

@bmschmidt bmschmidt force-pushed the remove_deferred_functions_queue branch from bc0cfea to 552887a Compare September 20, 2024 02:54
@bmschmidt bmschmidt force-pushed the 09-07-add_tuplemap_class branch from dd9bc11 to cd93751 Compare September 20, 2024 02:54
@bmschmidt bmschmidt changed the base branch from remove_deferred_functions_queue to graphite-base/139 September 20, 2024 03:05
@bmschmidt bmschmidt changed the base branch from graphite-base/139 to main September 20, 2024 03:07
@bmschmidt bmschmidt force-pushed the 09-07-add_tuplemap_class branch from cd93751 to 48c5da6 Compare September 20, 2024 03:09
@@ -82,3 +82,69 @@ function createDictionaryWithVector(

return returnval;
}

export class TupleMap<K = Object, V = Object> {
Copy link

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 {
Copy link

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.

@bmschmidt bmschmidt merged commit 43b574f into main Sep 20, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants