danlark1 / miniselect Goto Github PK
View Code? Open in Web Editor NEWSelection and partial sorting algorithms
License: Boost Software License 1.0
Selection and partial sorting algorithms
License: Boost Software License 1.0
Currently, it is size_t
, works well for most cases but not standard compliant
I was trying to replace my use of std::nth_element
with miniselect's implementation of Andrei Alexandrescu's adaptive quickselect, but I ran into an issue while doing so: it seems that one of the median_index
overloads does not consistently use the given comparator to compare elements (lines marked with HERE
):
template <class Iter, class Compare,
class DiffType = typename std::iterator_traits<Iter>::difference_type>
inline DiffType median_index(const Iter r, DiffType a, DiffType b, DiffType c,
Compare&& comp) {
if (r[a] > r[c]) std::swap(a, c); // HERE
if (r[b] > r[c]) return c; // HERE
if (comp(r[b], r[a])) return a;
return b;
}
I stumbled upon this issue while trying to sort with a custom predicate a collection of a type that doesn't have comparison operators, so I fortunately got into a compile-time error, but I believe that it can result into more subtle runtime errors too when the types to sort do implement comparison operators.
Anyway, thanks again for this library, I'm glad to see selection algorithms getting some love ๐
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.