Sort arbitrarily large data sets with a predictable amount of memory using temporary files.
import(
"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)
}
}
For more complex examples, please see our Documentation