radix: github.com/yourbasic/radix Index | Examples | Files

package radix

import "github.com/yourbasic/radix"

Package radix contains a string sorting algorithm.

This is an optimized sorting algorithm equivalent to sort.Strings. For string sorting, a carefully implemented radix sort can be considerably faster than Quicksort, sometimes more than twice as fast.

The algorithm uses O(n) extra space and runs in O(n+B) worst-case time, where n is the number of strings to be sorted and B is the number of bytes that must be inspected to sort the strings.



Package Files


func Sort Uses

func Sort(a []string)

Sort sorts a slice of strings in increasing byte-wise lexicographic order.

The function is equivalent to sort.Strings in the standard library.

func SortSlice Uses

func SortSlice(slice interface{}, str func(i int) string)

SortSlice sorts a slice according to the strings returned by str.

The function panics if the provided interface is not a slice.


people := []struct {
    Name string
    Age  int
    {"Gopher", 7},
    {"Alice", 55},
    {"Vera", 24},
    {"Bob", 75},
radix.SortSlice(people, func(i int) string { return people[i].Name })


[{Alice 55} {Bob 75} {Gopher 7} {Vera 24}]

Package radix imports 2 packages (graph). Updated 2019-07-10. Refresh now. Tools for package owners.