Ecosyste.ms: Packages

An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

Top 5.9% on proxy.golang.org
Top 2.8% dependent packages on proxy.golang.org
Top 2.9% dependent repos on proxy.golang.org
Top 9.8% forks on proxy.golang.org

proxy.golang.org : github.com/posener/order

Package order enables easier ordering and comparison tasks. This package provides functionality to easily define and apply order on values. It works out of the box for most primitive types and their pointer versions, and enable order of any object using (three-way comparison) https://en.wikipedia.org/wiki/Three-way_comparison with a given `func(T, T) int` function, or by implementing the generic interface: `func (T) Compare(T) int`. Supported Tasks: * [x] `Sort` / `SortStable` - sort a slice. * [x] `Search` - binary search for a value in a slice. * [x] `MinMax` - get indices of minimal and maximal values of a slice. * [X] `Is` - get a comparable object for more readable code. + [x] `Select` - get the K'th greatest value of a slice. * [x] `IsSorted` / `IsStrictSorted` - check if a slice is sorted. Order between values can be more forgiving than strict comparison. This library allows sensible type conversions. A type `U` can be used in order function of type `T` in the following cases: * `U` is a pointer (or pointers chain) to a `T`. * `T` is a pointer (or pointers chain) to a `U`. * `T` and `U` are of the same kind. * `T` and `U` are of the same number kind group (int?, uint?, float?, complex?) and `U`'s bits number is less or equal to `T`'s bits number. * `U` and `T` are assignable structs. Using this library might be less type safe - because of the usage of interfaces API, and less efficient - because of the use of reflection. On the other hand, this library reduce chances for errors by providing a well tested code and more readable code. See below how some order tasks can be translated to be used by this library. A simple example that shows how to use the order library with different basic types. A type may implement a `func (t T) Compare(other T) int` function. In this case it could be just used with the order package functions. An example of ordering struct with multiple fields with different priorities.

Registry - Source - Documentation - JSON
purl: pkg:golang/github.com/posener/order
Keywords: binary-search, comparable, compare, condition, go, golang, max, min, min-max, order, partition, pivot, search, select, sort
License: Apache-2.0
Latest release: about 4 years ago
First release: about 4 years ago
Namespace: github.com/posener
Dependent packages: 4
Dependent repositories: 3
Stars: 19 on GitHub
Forks: 3 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 24 days ago

    Loading...
    Readme
    Loading...