Skip to content

Strange Behavior of partialSort #46

Closed
@julmb

Description

@julmb

I have the following code:

module Main (main) where

import Data.Vector
import Data.Vector.Algorithms.Heap

go :: Vector Int -> Vector Int
go = modify $ \ v -> partialSort v 2

main :: IO ()
main = print $ go $ fromList [4, 3, 2, 1, 5]

The documentation of partialSort says:

Moves the lowest k elements to the front of the array, sorted.
The remaining values of the array will be in no particular order.

From this, I would expect this to give me [1, 2, ...]. However, I get [1, 3, 4, 5, 2].

Is this a bug or am I doing something wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions