GithubHelp home page GithubHelp logo

Add bit::sort and bit::stable_sort about bitlib HOT 1 OPEN

bkille avatar bkille commented on August 26, 2024
Add bit::sort and bit::stable_sort

from bitlib.

Comments (1)

nmcclatchey avatar nmcclatchey commented on August 26, 2024

Note that some efficiency is lost to ensure that elements not found within the range are not compared. Otherwise, the stable_sort algorithm would be:

  1. Perform two comparisons (compare(false,true) and compare(true,false)).
  2. If both comparisons are true, then the user has violated the contract of std::stable_sort by providing a comparator that does not implement a strict weak ordering. You are now authorized to deploy nasal demons (see "undefined behavior").
  3. If neither comparison is true, then all bits are incomparable, and should remain in their current order. Exit.
  4. Otherwise, count all set bits (this number will be referred to by the name "num_true")
  5. If number of set bits is either 0 or the size of the bit vector, the range is uniform (and thus sorted). Exit.
  6. Otherwise, if compare(false,true) evaluated to true, then unset the first size() - num_true bits, and set the final num_true bits.
  7. If compare(false,true) evaluated to false, then unset the num_true bits, and set the final size() - num_true bits.

from bitlib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.