frptools / collectable

High-performance immutable data structures for modern JavaScript and TypeScript applications. Functional interfaces, deep/composite operations API, mixed mutability API, TypeScript definitions, ES2015 module exports.
MIT License
273 stars 14 forks source link

Fix sorted map always using insertion order when created as mutable #70

Open AreeseDT opened 5 years ago

AreeseDT commented 5 years ago

Pass compare function to sorted map when calling empty using mutable overload.

axefrog commented 5 years ago

Hey thanks for the PR. Not ignoring you, you just caught me in a busy period and I need to reclone the repo and get up to date. I notice there is a build failure in Travis CI... if you are so inclined, perhaps you could take a look at the build log and let me know if you can see if it something that might be a problem?

AreeseDT commented 5 years ago

@axefrog The build errors have been resolved

eliranek1 commented 3 years ago

@AreeseDT, what's the use case that this is solving? I see that this is pretty old now, is this still necessary? also, can you please add some UTs?

AreeseDT commented 3 years ago

@eliranek1 When creating a mutable empty sorted map, the value of the comparator is never set. This means every mutable empty sorted map is always sorted in insertion order. The expected behavior of a mutable empty sorted map is that any items added are sorted by the provided comparator.

It would appear that this is a bug seeing as there are two function signature overloads with mutable: boolean|MutationContext and a ComparatorFn<SortedMapEntry<K, V, undefined>> parameter. The presence of the ComparatorFn<SortedMapEntry<K, V, undefined>> parameter shouldn't be ignored completely for mutable sorted maps correct?