Documentation ¶
Overview ¶
Example (Map) ¶
package main import ( "bytes" "fmt" "github.com/bsm/extsort" ) func main() { // Init with de-duplication. sorter := extsort.New(&extsort.Options{ Dedupe: bytes.Equal, }) defer sorter.Close() // Put key/value data. _ = sorter.Put([]byte("foo"), []byte("v1")) _ = sorter.Put([]byte("bar"), []byte("v2")) _ = sorter.Put([]byte("baz"), []byte("v3")) _ = sorter.Put([]byte("bar"), []byte("v4")) // duplicate _ = sorter.Put([]byte("dau"), []byte("v5")) // Sort and iterate. iter, err := sorter.Sort() if err != nil { panic(err) } defer iter.Close() for iter.Next() { fmt.Println(string(iter.Key()), string(iter.Value())) } if err := iter.Err(); err != nil { panic(err) } }
Output: bar v4 baz v3 dau v5 foo v1
Example (Plain) ¶
package main import ( "fmt" "github.com/bsm/extsort" ) func main() { // Init sorter. sorter := extsort.New(nil) defer sorter.Close() // Append plain data. _ = sorter.Append([]byte("foo")) _ = sorter.Append([]byte("bar")) _ = sorter.Append([]byte("baz")) _ = sorter.Append([]byte("dau")) // Sort and iterate. iter, err := sorter.Sort() if err != nil { panic(err) } defer iter.Close() for iter.Next() { fmt.Println(string(iter.Data())) } if err := iter.Err(); err != nil { panic(err) } }
Output: bar baz dau foo
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Compression ¶
type Compression uint8
Compression codec.
const ( CompressionNone Compression = iota CompressionGzip CompressionSnappy )
Supported compression types.
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator instances are used to iterate over sorted output.
type Options ¶
type Options struct { // WorkDir specifies the working directory. // By default os.TempDir() is used. WorkDir string // Keep temporary files until Close. // Default: Immediately remove temporary files. KeepFiles bool // Compare defines the compare function. // Default: bytes.Compare Compare Compare // Sort defines the sort function that is used. // Default: sort.Sort Sort func(sort.Interface) // Dedupe defines the compare function for de-duplication. // Default: nil (= do not de-dupe) // Keeps the last added item. Dedupe Equal // BufferSize limits the memory buffer used for sorting. // Default: 64MiB (must be at least 64KiB) BufferSize int // Compression optionally uses compression for temporary output. Compression Compression }
Options contains sorting options
type Sorter ¶
type Sorter struct {
// contains filtered or unexported fields
}
Sorter is responsible for sorting.
Click to show internal directories.
Click to hide internal directories.