borrow some code from stdlib to have bisect inserting in reversed order