package module
Version: v0.0.0-...-cbe1cc8 Latest Latest

Go to latest
Published: Mar 8, 2018 License: BSD-2-Clause

##### A fast string sorting algorithm

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

A discussion of MSD radix sort, its implementation and a comparison with other well-known sorting algorithms can be found in Implementing radixsort. In summary, MSD radix sort 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.

##### Installation

Once you have installed Go, run the `go get` command to install the `radix` package:

``````go get github.com/yourbasic/radix
``````
##### Documentation

There is an online reference for the package at godoc.org/github.com/yourbasic/radix.

Stefan Nilsson – korthaj

## Documentation ¶

### Overview ¶

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.

### Constants ¶

This section is empty.

### Variables ¶

This section is empty.

### Functions ¶

#### func Sort ¶

`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 ¶

`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.

Example
```package main

import (
"fmt"
)

func main() {
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 })
fmt.Println(people)
}
```
```Output:

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

### Types ¶

This section is empty.