Documentation
¶
Overview ¶
Example ¶
package main
import (
"context"
"fmt"
"github.com/bsm/streamsort"
)
func main() {
// Init a Sorter with default options
sorter := streamsort.New(nil)
defer sorter.Close()
// Append data
sorter.Append([]byte("foo"))
sorter.Append([]byte("bar"))
sorter.Append([]byte("baz"))
sorter.Append([]byte("boo"))
// Sort and iterate
iter, err := sorter.Sort(context.Background())
if err != nil {
panic(err)
}
defer iter.Close()
for iter.Next() {
fmt.Println(string(iter.Bytes()))
}
if err := iter.Err(); err != nil {
panic(err)
}
}
Output: bar baz boo foo
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Comparer ¶
type Comparer interface {
// Compare returns -1 when a is 'less than', 0 when a is 'equal to' or
// +1' when a is 'greater than' b.
Compare(a, b []byte) int
}
Comparer is used to compare data chunks for ordering
type ComparerFunc ¶
func (ComparerFunc) Compare ¶
func (f ComparerFunc) Compare(a, b []byte) int
type Compression ¶
type Compression uint8
const ( CompressionNone Compression = iota CompressionGzip )
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator allows to iterate over sorted outputs
type Options ¶
type Options struct {
// TempDir specifies the working directory.
// By default standard temp is used
TempDir string
// Compararer defines the sort order.
// Default: bytes.Compare
Comparer Comparer
// Compression is used for intermediate files.
// Default: CompressionNone
Compression Compression
// MaxOpenFiles limits the number of open files; must be >1.
// Default: 100
MaxOpenFiles int
// MaxMemBuffer limits the memory used for sorting
// Default: 64M (must be at least 1M = 1024*1024)
MaxMemBuffer int
}
Options contains sorting options
Click to show internal directories.
Click to hide internal directories.

