nth on range produces nonexistent values considering floating point

Description

Environment

None

Activity

Show:
David Nolen
July 24, 2020, 6:05 PM

Also see CLJS-3270

Mike Fikes
July 25, 2020, 8:21 PM
Edited

CLJS-3271.patch resolves the issue by having a specialized integer-specific finite range implementation which is both counted and indexed while leaving all other cases to a generic non-counted and non-indexed range implementation.

CLJS-3271.patch also resolves and includes a specific unit test for that case.

The "new" integer-specific finite range implementation is really just the old range implementation, renamed, and the new generic range implementation is largely derived from the old range implementation (removing ICounted and IIndexed and properly dealing with reducing and chunking, taking heavily from Clojure's implementation.)

With this patch, the (range) result produces a generic (non-counted, non-indexed) implementation and, relative to previously, it results in counted? returning false and applying count no longer immediately returns the maximum JavaScript integer value. Since it is no longer indexed, nth is no longer constant time on (range). To preserve indexed? behavior for (range) would likely require a dedicated typedef just for that use case. (So, strictly speaking, nth on (range)) is a perf regression with this patch, but is no worse than the current Clojure algorithmic complexity for the same.)

The coal mine tests suite, which makes heavy use of range, passes with CLJS-3271.patch.

Assignee

Mike Fikes

Reporter

Mike Fikes

Labels

None

Approval

Accepted

Patch

None

Priority

Major
Configure