sortof

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2023 License: MIT Imports: 6 Imported by: 0

README

sortof

Go Reference Quality check status

sortof provides implementations of peculiar carefully selected sorting algorithms as a:

  • CLI tool for sorting input, line by line (similar to POSIX sort),
  • Go module with functions for sorting slices (similar to slices.Sort()).

Implemented algorithms:

Usage

$ cat letters.txt
c
a
b
$ sortof bogo -t 10s letters.txt
a
b
c

Installation

Download latest stable release from GitHub .

You can also build it manually with commands: make && make build.

Development

Use make (GNU or BSD):

  • make - install dependencies
  • make test - runs test
  • make check - static code analysis
  • make build - compile binaries from latest commit
  • make dist - compile binaries from latest commit for supported OSes
  • make clean - removes compilation artifacts
  • make cli-release - tag latest commit as a new release of CLI
  • make module-release - tag latest commit as a new release of Go module
  • make info - print system info (useful for debugging).
Versioning

The repo contains CLI and Go module which can be developed with different pace. Commits with versions are tagged with:

License

MIT

Documentation

Overview

Package sortof provides functions for sorting slices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bogosort

func Bogosort[S ~[]E, E cmp.Ordered](ctx context.Context, x S) error

Bogosort sorts the slice x of any ordered type in ascending order. A context controls cancellation, because the worst-case time complexity is O(infinity). When sorting floating-point numbers, NaNs are ordered before other values.

See https://en.wikipedia.org/wiki/Bogosort.

func BogosortFunc

func BogosortFunc[S ~[]E, E any](ctx context.Context, x S, cmp func(a, b E) int) error

BogosortFunc sorts the slice x of any type in ascending order as determined by the cmp function. A context controls cancellation, because the worst-case time complexity is O(infinity). Function cmp(a, b) should return a negative number when a < b, a positive number when a > b and zero when a == b.

See https://en.wikipedia.org/wiki/Bogosort.

func Miraclesort added in v1.2.0

func Miraclesort[S ~[]E, E cmp.Ordered](ctx context.Context, x S) error

Miraclesort sorts the slice x of any ordered type in ascending order. A context controls cancellation, because miracles are non-deterministic and there is no guarantees, that slice will be ever sorted. When sorting floating-point numbers, NaNs are ordered before other values.

See https://en.wikipedia.org/wiki/Bogosort#Related_algorithms.

func MiraclesortFunc added in v1.2.0

func MiraclesortFunc[S ~[]E, E any](ctx context.Context, x S, cmp func(a, b E) int) error

MiraclesortFunc sorts the slice x of any type in ascending order as determined by the cmp function. A context controls cancellation, because miracles are non-deterministic and there is no guarantees, that slice will be ever sorted. Function cmp(a, b) should return a negative number when a < b, a positive number when a > b and zero when a == b.

See https://en.wikipedia.org/wiki/Bogosort#Related_algorithms.

func Slowsort

func Slowsort[S ~[]E, E cmp.Ordered](ctx context.Context, x S) error

Slowsort sorts the slice x of any ordered type in ascending order. It is practical implementation of multiply and surrender paradigm.

When sorting floating-point numbers, NaNs are ordered before other values. Cancelled context can leave slice partially ordered.

According to algorithm authors, slowsort is most suitable for hourly rated programmers.

See: Andrei Broder and Jorge Stolfi. Pessimal Algorithms and Simplexity Analysis. https://doi.org/10.1145/990534.990536

func SlowsortFunc

func SlowsortFunc[S ~[]E, E any](ctx context.Context, x S, cmp func(a, b E) int) error

SlowsortFunc sorts the slice x of any type in ascending order as determined by the cmp function. Function cmp(a, b) should return a negative number when a < b, a positive number when a > b and zero when a == b.

Cancelled context can leave slice partially ordered.

See: Andrei Broder and Jorge Stolfi. Pessimal Algorithms and Simplexity Analysis. https://doi.org/10.1145/990534.990536

func Stalinsort

func Stalinsort[S ~[]E, E cmp.Ordered](ctx context.Context, x S) (S, error)

Stalinsort returns slice created from x by deleting elements which are not in ascending order. For compatibility with other functions from package, context controls cancellation.

For floating-point types, a NaN is considered less than any non-NaN, a NaN is considered equal to a NaN, and -0.0 is equal to 0.0.

See https://mastodon.social/@mathew/100958177234287431.

func StalinsortFunc

func StalinsortFunc[S ~[]E, E any](ctx context.Context, x S, cmp func(a, b E) int) (S, error)

StalinsortFunc returns slice created from slice x by deleting elements which are not in order determined by the cmp function. For compatibility with other functions from package, context controls cancellation. Function cmp(a, b) should return a negative number when a < b, a positive number when a > b and zero when a == b.

See https://mastodon.social/@mathew/100958177234287431.

Types

This section is empty.

Directories

Path Synopsis
cmd
sortof
Command line interface for sorting lines of text files.
Command line interface for sorting lines of text files.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL