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

Feature request: Sorted Map #32

Open
vanodevium opened this issue May 2, 2023 · 2 comments
Open

Feature request: Sorted Map #32

vanodevium opened this issue May 2, 2023 · 2 comments

Comments

@vanodevium
Copy link

@zandaqo Thank you for your great work! These structures are awesome!

Could you please make a new data structure SortedMap? Or it is possible to do it from existing structures and I just didn't read it?

@zandaqo
Copy link
Owner

zandaqo commented May 7, 2023

Wouldn't a sorted array of objects be effectively that? Something like this:

class SortedMap<K, T> extends SortedArray<{ key: K, value: T}> {
  static compare<K, T>(a: { key: K, value: T}, b: { key: K, value: T}): -1 | 0 | 1 {
    if (a.key > b.key) return 1;
    if (a.key < b.key) return -1;
    if (a.key === b.key) return 0;
    throw new RangeError("Unstable comparison.");
  }
}

@vanodevium
Copy link
Author

This is a good choice, but not for all tasks.
I have a business logic where I have to store over 3M items and I really need a key-value structure for my business cases.

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

No branches or pull requests

2 participants