rangemin-2.2.1: Linear range-min algorithms.




equivVectorBy :: Vector v a => LEq a -> v a -> Vector IntSource

O(n). Given a comparison function and a lookup function, this function constructs a Vector Int with the property that the minimum index between i and j in the result vector is the same as the minimum index between i and j from the original elements. (In both cases, ties are broken by which index comes first.)

This allows us to use the specialized range-min implementation on Vector Int, even for other Vector implementations, other element types, and other comparison functions.

Internally, this function constructs the Cartesian tree of the input vector (implicitly, to save memory and stack space), and returns the vector of the depth of each element in the tree.