All Projects → Morwenn → Cpp Sort

Morwenn / Cpp Sort

Licence: mit
Sorting algorithms & related tools for C++14

Programming Languages

cpp
1120 projects
cpp17
186 projects
cpp14
131 projects

Projects that are alternatives of or similar to Cpp Sort

Sortingalgorithm.hayateshiki
Hayate-Shiki is an improved merge sort algorithm with the goal of "faster than quick sort".
Stars: ✭ 84 (-78.01%)
Mutual labels:  algorithm, sorting
Quadsort
Quadsort is a stable adaptive merge sort which is faster than quicksort.
Stars: ✭ 1,385 (+262.57%)
Mutual labels:  algorithm, sorting
Cpp Timsort
A C++ implementation of timsort
Stars: ✭ 211 (-44.76%)
Mutual labels:  algorithm, sorting
Jstarcraft Rns
专注于解决推荐领域与搜索领域的两个核心问题:排序预测(Ranking)和评分预测(Rating). 为相关领域的研发人员提供完整的通用设计与参考实现. 涵盖了70多种排序预测与评分预测算法,是最快最全的Java推荐与搜索引擎.
Stars: ✭ 324 (-15.18%)
Mutual labels:  algorithm
Homemade Machine Learning
🤖 Python examples of popular machine learning algorithms with interactive Jupyter demos and math being explained
Stars: ✭ 18,594 (+4767.54%)
Mutual labels:  algorithm
Free Programming Books
📚码农周报 免费的编程书籍,leetcode(力扣)题解、前端算法题,牛客网前端大厂面试题题解、提升工作效率的常用工具等📈🎉
Stars: ✭ 345 (-9.69%)
Mutual labels:  algorithm
Algorithms
Minimal examples of data structures and algorithms in Python
Stars: ✭ 20,123 (+5167.8%)
Mutual labels:  algorithm
Algorithms
All algorithms writing with javascript in the book 'Algorithms Fourth Edition'.
Stars: ✭ 322 (-15.71%)
Mutual labels:  algorithm
Code Test Study
코딩 테스트 관련 기출문항을 풀어보고 소스코드 및 설명을 업로드합니다. (문제 추천은 Discussions에 들어가셔서 자유롭게 가능합니다.)
Stars: ✭ 344 (-9.95%)
Mutual labels:  algorithm
Fbp
FBP项目全称FootBallPrediction,历经9个月完成的足球比赛预测项目。项目结合大数据+机器学习,不断摸索开发了一个程序。程序根据各大公司赔率多维度预测足球比赛结果(包含胜和不胜)。机器学习用的是自己建立的“三木板模型”算法,已在国家期刊发表论文并被万方数据库收录,详见_ML_文件。目前准确率可达80%。该项目在自己创建的微信群里已经吸引了很多人,附件为群讨论截图,并且每天均有部分人根据预测结果参考投注竞彩,参考的人都获得了相应的收益。 现在想通过认识更多的有识之士,一起探索如何将项目做大做强,找到合伙人,实现共赢。希望感兴趣的同仁联系本人,微信号acredjb。公众号AI金胆(或AI-FBP),每天都有程序预测的足球比赛。程序优势请看Advantages和README文件。程序3.0版本:(第三轮目前13中12) 8月10日:13让负(正确) 8月11日:27让负(正确) 8月12日:11让负(正确) 8月13日:6胜(不正确) 8月14日:25让负(正确) 8月15日:无预测 8月16日:1胜(正确) 8月17日:6让负(正确) 8月18日:16胜(正确) 8月19日:34让负(正确) ... 1.0版本(第一轮为11中9) 2.0版本(第二轮13中11).
Stars: ✭ 337 (-11.78%)
Mutual labels:  algorithm
Tech Interview For Developer
👶🏻 신입 개발자 전공 지식 & 기술 면접 백과사전 📖
Stars: ✭ 5,610 (+1368.59%)
Mutual labels:  algorithm
Interview
📚 C/C++ 技术面试基础知识总结,包括语言、程序库、数据结构、算法、系统、网络、链接装载库等知识及面试经验、招聘、内推等信息。This repository is a summary of the basic knowledge of recruiting job seekers and beginners in the direction of C/C++ technology, including language, program library, data structure, algorithm, system, network, link loading library, interview experience, recruitment, recommendatio…
Stars: ✭ 21,608 (+5556.54%)
Mutual labels:  algorithm
Data Structure
基于java语言的数据结构及算法实现,LeetCode算法示例
Stars: ✭ 348 (-8.9%)
Mutual labels:  algorithm
Tinyqueue
The smallest and simplest priority queue in JavaScript.
Stars: ✭ 322 (-15.71%)
Mutual labels:  algorithm
Cs Wiki
🎉 致力打造完善的 Java 后端知识体系,不仅仅帮助各位小伙伴快速且系统的准备面试,更指引学习的方向
Stars: ✭ 369 (-3.4%)
Mutual labels:  algorithm
Gate And Cse Resources For Students
📚 📖 📚CSE GATE Resources for GATE and CSE Aspirants 😎 😁 . Show your ❤️ by ⭐️⭐️
Stars: ✭ 321 (-15.97%)
Mutual labels:  algorithm
Tbox
🎁 A glib-like multi-platform c library
Stars: ✭ 3,800 (+894.76%)
Mutual labels:  algorithm
Machine learning basics
Plain python implementations of basic machine learning algorithms
Stars: ✭ 3,557 (+831.15%)
Mutual labels:  algorithm
Ojalgo
oj! Algorithms
Stars: ✭ 336 (-12.04%)
Mutual labels:  algorithm
Delaunay Triangulation
C++ version the delaunay triangulation
Stars: ✭ 339 (-11.26%)
Mutual labels:  algorithm

Latest Release Conan Package Code Coverage

It would be nice if only one or two of the sorting methods would dominate all of the others, regardless of application or the computer being used. But in fact, each method has its own peculiar virtues. [...] Thus we find that nearly all of the algorithms deserve to be remembered, since there are some applications in which they turn out to be best. — Donald Knuth, The Art Of Computer Programming, Volume 3

cpp-sort is a generic C++14 header-only sorting library. It revolves around one main generic sorting interface and provides several small tools to pick and/or design sorting algorithms. Using its basic sorting features should be trivial enough:

#include <array>
#include <iostream>
#include <cpp-sort/sorters/smooth_sorter.h>

int main()
{
    std::array<int, 5> arr = { 5, 8, 3, 2, 9 };
    cppsort::smooth_sort(arr);

    // prints 2 3 5 8 9
    for (int val: arr) {
        std::cout << val << ' ';
    }
}

The main features & the extra features

cpp-sort provides a full set of sorting-related features. Here are the main building blocks of the library:

Here is a more complete example of what can be done with the library:

#include <algorithm>
#include <cassert>
#include <forward_list>
#include <functional>
#include <iterator>
#include <vector>
#include <cpp-sort/adapters.h>
#include <cpp-sort/sorters.h>

int main()
{
    struct wrapper { int value; };

    std::forward_list<wrapper> li = { {5}, {8}, {3}, {2}, {9} };
    std::vector<wrapper> vec = { {5}, {8}, {3}, {2}, {9} };

    // When used, this sorter will use a pattern-defeating quicksort
    // to sort random-access collections, and a mergesort otherwise
    cppsort::hybrid_adapter<
        cppsort::pdq_sorter,
        cppsort::merge_sorter
    > sorter;

    // Sort li and vec in reverse order using their value member
    sorter(li, std::greater<>{}, &wrapper::value);
    sorter(vec, std::greater<>{}, &wrapper::value);

    assert(std::equal(
        std::begin(li), std::end(li),
        std::begin(vec), std::end(vec),
        [](auto& lhs, auto& rhs) { return lhs.value == rhs.value; }
    ));
}

Even when the sorting functions are used without the extra features, they still provide some interesting guarantees (ideas often taken from the Ranges TS):

  • They provide both an iterator and a range interface
  • When possible, they accept a custom comparator parameter
  • Most of them accept a projection parameter
  • They correctly handle proxy iterators with iter_swap and iter_move
  • They also work when iterators don't provide post-incrementation nor post-decrementation
  • The value types of the collections to be sorted need not be default-constructible
  • The value types of the collections to be sorted need not be copyable (only movable)
  • Stateless sorters can be converted to a function pointer for each overloaded operator()
  • Sorters are function objects: they can directly be passed as "overload sets" to other functions

You can read more about all the available tools and find some tutorials about using and extending cpp-sort in the wiki.

Benchmarks

The following graph has been generated with a script found in the benchmarks directory. It shows the time needed for a sorting algorithm to sort one million shuffled std::array<int, N> of sizes 0 to 32. It compares the sorters generally used to sort small arrays:

Benchmark speed of small sorts with increasing size for std::array<int>

These results were generated with MinGW-w64 g++ 10.1 with the compiler options -std=c++2a -O3 -march=native. That benchmark is merely an example to make this introduction look good. You can find more commented benchmarks in the dedicated wiki page.

Compiler support & tooling

Ubuntu builds status Windows builds status MacOS builds status

cpp-sort currently requires C++14 support, and only works with g++5 and clang++3.8 or more recent versions of these compilers. So far, the library should work with the following compilers:

  • g++5.5 or more recent. It is known not to work with some older g++5 versions.
  • clang++6 or more recent. It should work with clang++ versions all the way back to 3.8, but the CI pipeline doesn't have test for those anymore.
  • Visual Studio 2019 version 16.8.3 or more recent, only with /permissive-. A few features are unavailable.
  • The versions of MinGW-w64 and AppleClang equivalent to the compilers mentioned above.
  • Clang is notably tested with both libstdc++ and libc++.

The compilers listed above are the ones used by the CI pipeline, and the library is also tested with the most recent versions of those compilers on a regular basis. All the other compiler versions in-between are untested, but should also work. Feel free to open an issue if it isn't the case.

The features in the library might differ depending on the C++ version used and on the compiler extensions enabled. Those changes are documented in the wiki.

The main repository contains additional support for standard tooling such as CMake or Conan. You can read more about those in the wiki.

Thanks

I got a new car. I just need to put it together. They’re easier to steal piece by piece. — Jarod Kintz, $3.33

Even though some parts of the library are original research and some others correspond to custom and rather naive implementations of standard sorting algorithms, cpp-sort also reuses a great deal of code and ideas from open-source projects, often altered to integrate seamlessly into the library. Here is a list of the external resources used to create this library. I hope that the many different licenses are compatible. If it is not the case, please contact me (or submit an issue) and we will see what can be done about it:

  • Some of the algorithms used by insertion_sorter and pdq_sorter come from Orson Peters' pattern-defeating quicksort. Some parts of the benchmarks come from there as well.

  • The algorithm used by tim_sorter comes from Goro Fuji's (gfx) implementation of a Timsort.

  • The three algorithms used by spread_sorter come from Steven Ross Boost.Sort module.

  • utility::as_function, utility::static_const, and several projection-enhanced helper algorithms come from Eric Niebler's Range v3 library. Several ideas such as proxy iterators, customization points and projections, as well as a few other utility functions also come from that library or from the related articles and standard C++ proposals.

  • The algorithm used by ska_sorter comes from Malte Skarupke's implementation of his own ska_sort algorithm.

  • The algorithm used by drop_merge_sorter comes from Adrian Wielgosik C++ reimplementation of Emil Ernerfeldt's drop-merge sort.

  • Many enhanced standard algorithms are directly adapted from their counterparts in libc++, enhanced to handle both projections and proxy iterators.

  • The library internally uses an inplace_merge function that works with forward iterators. Its implementation uses a merge algorithm proposed by Dudziński and Dydek, and implemented by Alexander Stepanov and Paul McJones in their book Elements of Programming.

  • The inplace_merge overload for random-access iterators uses the Symmerge algorithm proposed by Pok-Son Kim and Arne Kutzner in Stable Minimum Storage Merging by Symmetric Comparisons when there isn't enough memory available to perform an out-of-place merge.

  • The implementation of Dijkstra's smoothsort used by smooth_sorter has been directly adapted from Keith Schwarz's implementation of the algorithm.

  • The algorithm used by block_sorter has been adapted from BonzaiThePenguin's WikiSort.

  • The algorithm used by grail_sorter has been adapted from Mrrl's GrailSort, hence the name.

  • The algorithm used by indirect_adapter with forward or bidirectional iterators is a slightly modified version of Matthew Bentley's indiesort.

  • The implementation of the random-access overload of nth_element used by some of the algorithms comes from Danila Kutenin's miniselect library and uses Andrei Alexandrescu's AdaptiveQuickselect algorithm.

  • The algorithms 0 to 16 used by sorting_network_sorter have been generated with Perl's Algorithm::Networksort module.

  • The algorithm 17 used by sorting_network_sorter correspond to the ones found by Symmetry and Evolution based Network Sort Optimization (SENSO) published in Using Symmetry and Evolutionary Search to Minimize Sorting Networks by Valsalam and Miikkulainen.

  • The algorithms 18 to 26 and 28 used by sorting_network_sorter have been found and proposed for inclusion by Bert Dobbelaere with his SorterHunter project. Huge thanks for this contribution :) You can find a full list of most well-known sorting networks up to 32 inputs on his website.

  • Some of the optimizations used by sorting_network_sorter come from this discussion on StackOverflow and are backed by the article Applying Sorting Networks to Synthesize Optimized Sorting Libraries.

  • The LaTeX scripts used to draw the sorting networks are modified versions of kaayy's sortingnetwork.tex, slightly adapted to be 0-based and draw the network from top to bottom.

  • The CMake tools embedded in the projects include scripts from RWTH-HPC/CMake-codecov and Crascit/DownloadProject.

  • Some of the benchmarks use a colorblind-friendly palette developed by Thøger Rivera-Thorsen.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].