GithubHelp home page GithubHelp logo

slightlyoutofphase / staticsort Goto Github PK

View Code? Open in Web Editor NEW
7.0 7.0 1.0 62 KB

Implements a macro providing a compile-time quicksort function for arrays of any length, containing any primitive Copy type with a PartialOrd implementation.

License: Apache License 2.0

Rust 76.25% Batchfile 1.48% Shell 22.28%
algorithms compile-time const crates ctfe macro no-std partialord quick-sort quicksort rust sort sorting

staticsort's People

Contributors

jakubkoralewski avatar slightlyoutofphase avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

jakubkoralewski

staticsort's Issues

Expose `impl_static_sorter` macro?

Would you consider exposing the impl_static_sorter macro?

With const_trait_impl feature, it's possible to create a const impl of PartialOrd for a user-defined type. It would then be possible use staticsort to sort this type.

This would work:

#![feature(const_trait_impl)]

use std::cmp::Ordering;
use staticsort::{staticsort, impl_static_sorter};

#[derive(Copy, Clone, Debug, PartialEq)]
struct Foo {
    inner: u32,
}

impl const PartialOrd for Foo {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(if self.inner < other.inner {
            Ordering::Less
        } else if self.inner > other.inner {
            Ordering::Greater
        } else {
            Ordering::Equal
        })
    }
}

impl_static_sorter!(Foo);

const FOOS: [Foo; 3] = [Foo { inner: 3 }, Foo { inner: 2 }, Foo { inner: 1 }];
const FOOS_SORTED: [Foo; 3] = staticsort!(Foo, 0, 2, FOOS);

If you'd be open to this, I'd be happy to make a PR.

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.