Skip to content

flipM is unnecessarily slow #71

@ChickenProp

Description

@ChickenProp

I noticed that flipM is implemented with flipAL, which uses Eq constraints. I think it's O(n^2) but could instead be O(n log n) with something like

flipM = Map.fromListWith (++) . map (\(k, v) -> (v, [k])) . Map.toList

There are details to check here: are the values in the new map in the same order as with the current implementation? What kind of efficiency does it have if every value in the original map is equal? I think the answers are "yes" and "O(n)" respectively, but that's just from a quick glance. Even if it's not quite right, something like this should be possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions