Skip to content

More efficient fromList for sets and maps #1128

Open
@meooow25

Description

@meooow25

Originally proposed and implemented for IntMap in #653 by @treeowl.

fromList is repeated insert. insert goes down the tree to the insertion position, then back up to the root.
The idea is that from the insertion position we go to the next insertion position directly instead of up to the root.

This means that the total time of fromList is the sum of the distances on the tree between adjacent elements. Clusters of adjacent elements will take linear time to insert. If the list is ascending or descending, the entire function is linear time. The worst case remains the same as before, we may still need to go up to the root for every element.

For IntSet/IntMap, that is all there is to it. For Set/Map, we have a problem that repeatedly inserting at a position will make the tree unbalanced. To fix this, it should be possible to go up towards the root restoring balance until there are no unbalanced nodes, then going to the next insertion position as usual.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions