Fix worst-case quadratic behavior of iterator constructors and range insert()
authorMark Logan <mlogan@fb.com>
Fri, 3 Feb 2017 18:09:52 +0000 (10:09 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 3 Feb 2017 18:18:01 +0000 (10:18 -0800)
commit3ffcb010fb7333a9ad6b233b47e1ecfdfb0fc2f0
treeacf2d11e80faa04889774372afd66d36b7cdced2
parent30db459fbc305767647753f41f4cc63c5c8ba3b9
Fix worst-case quadratic behavior of iterator constructors and range insert()

Summary:
The iterator constructors and the range insert() method previously
had quadratic runtime if given an unsorted range. This is now fixed. We
append the entire range to the container, sort that subrange, and merge it
into the already-sorted container. Sorting and merging is skipped when possible.

Reviewed By: yfeldblum

Differential Revision: D4493534

fbshipit-source-id: e6d73b5c19e374001f9e340ff527c5257bef2ca3
folly/sorted_vector_types.h
folly/test/sorted_vector_test.cpp