bufio

package
v0.0.0-...-5012a73 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PipeLines

func PipeLines(inp <-chan os.File) (out <-chan string)

PipeLines - an experiment

func ReadWriters

func ReadWriters(inp1 <-chan *bufio.Reader, inp2 <-chan *bufio.Writer) (out <-chan *bufio.ReadWriter)

ReadWriters - (r *Reader, w *Writer) *ReadWriter

func ReaderSize

func ReaderSize(inp <-chan io.Reader, size int) (out <-chan *bufio.Reader)

ReaderSize - (w io.Reader, size int) *Reader

func Readers

func Readers(inp <-chan io.Reader) (out <-chan *bufio.Reader)

Readers - (w io.Reader) *Reader

func Scanners

func Scanners(inp <-chan io.Reader) (out <-chan *bufio.Scanner)

Scanners - (r io.Reader) *Scanner

func WriterSize

func WriterSize(inp <-chan io.Writer, size int) (out <-chan *bufio.Writer)

WriterSize - (w io.Writer, size int) *Writer

func Writers

func Writers(inp <-chan io.Writer) (out <-chan *bufio.Writer)

Writers - (w io.Writer) *Writer

Types

type ReadWriterPile

type ReadWriterPile struct {
	// contains filtered or unexported fields
}

ReadWriterPile is a hybrid container for a lazily and concurrently populated growing-only slice of items (of type `*bufio.ReadWriter`) which may be traversed in parallel to it's growth.

Usage for a pile `p`:

p := MakeReadWriterPile(128, 32)

Have it grow concurrently using multiple:

var item *bufio.ReadWriter = something
p.Pile(item)

in as many go routines as You may seem fit.

In parallel, You may either traverse `p` in parallel right away:

for item, ok := p.Iter(); ok; item, ok = p.Next() { ... do sth with item ... }

Here p.Iter() starts a new transversal with the first item (if any), and p.Next() keeps traverses the ReadWriterPile.

or traverse blocking / awaiting close first:

for item := range <-p.Done() { ... do sth with item ... }

or use the result when available:

r, p := <-p.Done(), nil

Hint: here we get the result in `r` and at the same time discard / deallocate / forget the pile `p` itself.

Note: The traversal is *not* intended to be concurrency safe! Thus: You may call `Pile` concurrently to Your traversal, but use of either `Done` or `Iter` and `Next` *must* be confined to a single go routine (thread).

func MakeReadWriterPile

func MakeReadWriterPile(size, buff int) *ReadWriterPile

MakeReadWriterPile returns a (pointer to a) fresh pile of items (of type `*bufio.ReadWriter`) with size as initial capacity and with buff as initial leeway, allowing as many Pile's to execute non-blocking before respective Done or Next's.

func (*ReadWriterPile) Close

func (d *ReadWriterPile) Close() (err error)

Close - call once when everything has been piled.

Close intentionally implements io.Closer

Note: After Close(), any Close(...) will panic and any Pile(...) will panic and any Done() or Next() will return immediately: no eventual blocking, that is.

func (*ReadWriterPile) Done

func (d *ReadWriterPile) Done() (done <-chan []*bufio.ReadWriter)

Done returns a channel which emits the result (as slice of ReadWriter) once the pile is closed.

Users of Done() *must not* iterate (via Iter() Next()...) before the done-channel is closed!

Done is a convenience - useful iff You do not like/need to start any traversal before the pile is fully populated. Once the pile is closed, Done() will signal in constant time.

Note: Upon signalling, the pile is reset to it's tip, so You may traverse it (via Next) right away. Usage for a pile `p`: Traverse blocking / awaiting close first:

for item := range <-p.Done() { ... do sth with item ... }

or use the result when available

r, p := <-p.Done(), nil

while discaring the pile itself.

func (*ReadWriterPile) Iter

func (d *ReadWriterPile) Iter() (item *bufio.ReadWriter, ok bool)

Iter puts the pile iterator back to the beginning and returns the first `Next()`, iff any. Usage for a pile `p`:

for item, ok := p.Iter(); ok; item, ok = p.Next() { ... do sth with item ... }

func (*ReadWriterPile) Next

func (d *ReadWriterPile) Next() (item *bufio.ReadWriter, ok bool)

Next returns the next item, or false iff the pile is exhausted.

Note: Iff the pile is not closed yet, Next may block, awaiting some Pile().

func (*ReadWriterPile) Pile

func (d *ReadWriterPile) Pile(item *bufio.ReadWriter)

Pile appends an `*bufio.ReadWriter` item to the ReadWriterPile.

Note: Pile will block iff buff is exceeded and no Done() or Next()'s are used.

type ReaderPile

type ReaderPile struct {
	// contains filtered or unexported fields
}

ReaderPile is a hybrid container for a lazily and concurrently populated growing-only slice of items (of type `*bufio.Reader`) which may be traversed in parallel to it's growth.

Usage for a pile `p`:

p := MakeReaderPile(128, 32)

Have it grow concurrently using multiple:

var item *bufio.Reader = something
p.Pile(item)

in as many go routines as You may seem fit.

In parallel, You may either traverse `p` in parallel right away:

for item, ok := p.Iter(); ok; item, ok = p.Next() { ... do sth with item ... }

Here p.Iter() starts a new transversal with the first item (if any), and p.Next() keeps traverses the ReaderPile.

or traverse blocking / awaiting close first:

for item := range <-p.Done() { ... do sth with item ... }

or use the result when available:

r, p := <-p.Done(), nil

Hint: here we get the result in `r` and at the same time discard / deallocate / forget the pile `p` itself.

Note: The traversal is *not* intended to be concurrency safe! Thus: You may call `Pile` concurrently to Your traversal, but use of either `Done` or `Iter` and `Next` *must* be confined to a single go routine (thread).

func MakeReaderPile

func MakeReaderPile(size, buff int) *ReaderPile

MakeReaderPile returns a (pointer to a) fresh pile of items (of type `*bufio.Reader`) with size as initial capacity and with buff as initial leeway, allowing as many Pile's to execute non-blocking before respective Done or Next's.

func (*ReaderPile) Close

func (d *ReaderPile) Close() (err error)

Close - call once when everything has been piled.

Close intentionally implements io.Closer

Note: After Close(), any Close(...) will panic and any Pile(...) will panic and any Done() or Next() will return immediately: no eventual blocking, that is.

func (*ReaderPile) Done

func (d *ReaderPile) Done() (done <-chan []*bufio.Reader)

Done returns a channel which emits the result (as slice of Reader) once the pile is closed.

Users of Done() *must not* iterate (via Iter() Next()...) before the done-channel is closed!

Done is a convenience - useful iff You do not like/need to start any traversal before the pile is fully populated. Once the pile is closed, Done() will signal in constant time.

Note: Upon signalling, the pile is reset to it's tip, so You may traverse it (via Next) right away. Usage for a pile `p`: Traverse blocking / awaiting close first:

for item := range <-p.Done() { ... do sth with item ... }

or use the result when available

r, p := <-p.Done(), nil

while discaring the pile itself.

func (*ReaderPile) Iter

func (d *ReaderPile) Iter() (item *bufio.Reader, ok bool)

Iter puts the pile iterator back to the beginning and returns the first `Next()`, iff any. Usage for a pile `p`:

for item, ok := p.Iter(); ok; item, ok = p.Next() { ... do sth with item ... }

func (*ReaderPile) Next

func (d *ReaderPile) Next() (item *bufio.Reader, ok bool)

Next returns the next item, or false iff the pile is exhausted.

Note: Iff the pile is not closed yet, Next may block, awaiting some Pile().

func (*ReaderPile) Pile

func (d *ReaderPile) Pile(item *bufio.Reader)

Pile appends an `*bufio.Reader` item to the ReaderPile.

Note: Pile will block iff buff is exceeded and no Done() or Next()'s are used.

type ScannerPile

type ScannerPile struct {
	// contains filtered or unexported fields
}

ScannerPile is a hybrid container for a lazily and concurrently populated growing-only slice of items (of type `*bufio.Scanner`) which may be traversed in parallel to it's growth.

Usage for a pile `p`:

p := MakeScannerPile(128, 32)

Have it grow concurrently using multiple:

var item *bufio.Scanner = something
p.Pile(item)

in as many go routines as You may seem fit.

In parallel, You may either traverse `p` in parallel right away:

for item, ok := p.Iter(); ok; item, ok = p.Next() { ... do sth with item ... }

Here p.Iter() starts a new transversal with the first item (if any), and p.Next() keeps traverses the ScannerPile.

or traverse blocking / awaiting close first:

for item := range <-p.Done() { ... do sth with item ... }

or use the result when available:

r, p := <-p.Done(), nil

Hint: here we get the result in `r` and at the same time discard / deallocate / forget the pile `p` itself.

Note: The traversal is *not* intended to be concurrency safe! Thus: You may call `Pile` concurrently to Your traversal, but use of either `Done` or `Iter` and `Next` *must* be confined to a single go routine (thread).

func MakeScannerPile

func MakeScannerPile(size, buff int) *ScannerPile

MakeScannerPile returns a (pointer to a) fresh pile of items (of type `*bufio.Scanner`) with size as initial capacity and with buff as initial leeway, allowing as many Pile's to execute non-blocking before respective Done or Next's.

func (*ScannerPile) Close

func (d *ScannerPile) Close() (err error)

Close - call once when everything has been piled.

Close intentionally implements io.Closer

Note: After Close(), any Close(...) will panic and any Pile(...) will panic and any Done() or Next() will return immediately: no eventual blocking, that is.

func (*ScannerPile) Done

func (d *ScannerPile) Done() (done <-chan []*bufio.Scanner)

Done returns a channel which emits the result (as slice of Scanner) once the pile is closed.

Users of Done() *must not* iterate (via Iter() Next()...) before the done-channel is closed!

Done is a convenience - useful iff You do not like/need to start any traversal before the pile is fully populated. Once the pile is closed, Done() will signal in constant time.

Note: Upon signalling, the pile is reset to it's tip, so You may traverse it (via Next) right away. Usage for a pile `p`: Traverse blocking / awaiting close first:

for item := range <-p.Done() { ... do sth with item ... }

or use the result when available

r, p := <-p.Done(), nil

while discaring the pile itself.

func (*ScannerPile) Iter

func (d *ScannerPile) Iter() (item *bufio.Scanner, ok bool)

Iter puts the pile iterator back to the beginning and returns the first `Next()`, iff any. Usage for a pile `p`:

for item, ok := p.Iter(); ok; item, ok = p.Next() { ... do sth with item ... }

func (*ScannerPile) Next

func (d *ScannerPile) Next() (item *bufio.Scanner, ok bool)

Next returns the next item, or false iff the pile is exhausted.

Note: Iff the pile is not closed yet, Next may block, awaiting some Pile().

func (*ScannerPile) Pile

func (d *ScannerPile) Pile(item *bufio.Scanner)

Pile appends an `*bufio.Scanner` item to the ScannerPile.

Note: Pile will block iff buff is exceeded and no Done() or Next()'s are used.

type SplitFuncPile

type SplitFuncPile struct {
	// contains filtered or unexported fields
}

SplitFuncPile is a hybrid container for a lazily and concurrently populated growing-only slice of items (of type `bufio.SplitFunc`) which may be traversed in parallel to it's growth.

Usage for a pile `p`:

p := MakeSplitFuncPile(128, 32)

Have it grow concurrently using multiple:

var item bufio.SplitFunc = something
p.Pile(item)

in as many go routines as You may seem fit.

In parallel, You may either traverse `p` in parallel right away:

for item, ok := p.Iter(); ok; item, ok = p.Next() { ... do sth with item ... }

Here p.Iter() starts a new transversal with the first item (if any), and p.Next() keeps traverses the SplitFuncPile.

or traverse blocking / awaiting close first:

for item := range <-p.Done() { ... do sth with item ... }

or use the result when available:

r, p := <-p.Done(), nil

Hint: here we get the result in `r` and at the same time discard / deallocate / forget the pile `p` itself.

Note: The traversal is *not* intended to be concurrency safe! Thus: You may call `Pile` concurrently to Your traversal, but use of either `Done` or `Iter` and `Next` *must* be confined to a single go routine (thread).

func MakeSplitFuncPile

func MakeSplitFuncPile(size, buff int) *SplitFuncPile

MakeSplitFuncPile returns a (pointer to a) fresh pile of items (of type `bufio.SplitFunc`) with size as initial capacity and with buff as initial leeway, allowing as many Pile's to execute non-blocking before respective Done or Next's.

func (*SplitFuncPile) Close

func (d *SplitFuncPile) Close() (err error)

Close - call once when everything has been piled.

Close intentionally implements io.Closer

Note: After Close(), any Close(...) will panic and any Pile(...) will panic and any Done() or Next() will return immediately: no eventual blocking, that is.

func (*SplitFuncPile) Done

func (d *SplitFuncPile) Done() (done <-chan []bufio.SplitFunc)

Done returns a channel which emits the result (as slice of SplitFunc) once the pile is closed.

Users of Done() *must not* iterate (via Iter() Next()...) before the done-channel is closed!

Done is a convenience - useful iff You do not like/need to start any traversal before the pile is fully populated. Once the pile is closed, Done() will signal in constant time.

Note: Upon signalling, the pile is reset to it's tip, so You may traverse it (via Next) right away. Usage for a pile `p`: Traverse blocking / awaiting close first:

for item := range <-p.Done() { ... do sth with item ... }

or use the result when available

r, p := <-p.Done(), nil

while discaring the pile itself.

func (*SplitFuncPile) Iter

func (d *SplitFuncPile) Iter() (item bufio.SplitFunc, ok bool)

Iter puts the pile iterator back to the beginning and returns the first `Next()`, iff any. Usage for a pile `p`:

for item, ok := p.Iter(); ok; item, ok = p.Next() { ... do sth with item ... }

func (*SplitFuncPile) Next

func (d *SplitFuncPile) Next() (item bufio.SplitFunc, ok bool)

Next returns the next item, or false iff the pile is exhausted.

Note: Iff the pile is not closed yet, Next may block, awaiting some Pile().

func (*SplitFuncPile) Pile

func (d *SplitFuncPile) Pile(item bufio.SplitFunc)

Pile appends an `bufio.SplitFunc` item to the SplitFuncPile.

Note: Pile will block iff buff is exceeded and no Done() or Next()'s are used.

type WriterPile

type WriterPile struct {
	// contains filtered or unexported fields
}

WriterPile is a hybrid container for a lazily and concurrently populated growing-only slice of items (of type `*bufio.Writer`) which may be traversed in parallel to it's growth.

Usage for a pile `p`:

p := MakeWriterPile(128, 32)

Have it grow concurrently using multiple:

var item *bufio.Writer = something
p.Pile(item)

in as many go routines as You may seem fit.

In parallel, You may either traverse `p` in parallel right away:

for item, ok := p.Iter(); ok; item, ok = p.Next() { ... do sth with item ... }

Here p.Iter() starts a new transversal with the first item (if any), and p.Next() keeps traverses the WriterPile.

or traverse blocking / awaiting close first:

for item := range <-p.Done() { ... do sth with item ... }

or use the result when available:

r, p := <-p.Done(), nil

Hint: here we get the result in `r` and at the same time discard / deallocate / forget the pile `p` itself.

Note: The traversal is *not* intended to be concurrency safe! Thus: You may call `Pile` concurrently to Your traversal, but use of either `Done` or `Iter` and `Next` *must* be confined to a single go routine (thread).

func MakeWriterPile

func MakeWriterPile(size, buff int) *WriterPile

MakeWriterPile returns a (pointer to a) fresh pile of items (of type `*bufio.Writer`) with size as initial capacity and with buff as initial leeway, allowing as many Pile's to execute non-blocking before respective Done or Next's.

func (*WriterPile) Close

func (d *WriterPile) Close() (err error)

Close - call once when everything has been piled.

Close intentionally implements io.Closer

Note: After Close(), any Close(...) will panic and any Pile(...) will panic and any Done() or Next() will return immediately: no eventual blocking, that is.

func (*WriterPile) Done

func (d *WriterPile) Done() (done <-chan []*bufio.Writer)

Done returns a channel which emits the result (as slice of Writer) once the pile is closed.

Users of Done() *must not* iterate (via Iter() Next()...) before the done-channel is closed!

Done is a convenience - useful iff You do not like/need to start any traversal before the pile is fully populated. Once the pile is closed, Done() will signal in constant time.

Note: Upon signalling, the pile is reset to it's tip, so You may traverse it (via Next) right away. Usage for a pile `p`: Traverse blocking / awaiting close first:

for item := range <-p.Done() { ... do sth with item ... }

or use the result when available

r, p := <-p.Done(), nil

while discaring the pile itself.

func (*WriterPile) Iter

func (d *WriterPile) Iter() (item *bufio.Writer, ok bool)

Iter puts the pile iterator back to the beginning and returns the first `Next()`, iff any. Usage for a pile `p`:

for item, ok := p.Iter(); ok; item, ok = p.Next() { ... do sth with item ... }

func (*WriterPile) Next

func (d *WriterPile) Next() (item *bufio.Writer, ok bool)

Next returns the next item, or false iff the pile is exhausted.

Note: Iff the pile is not closed yet, Next may block, awaiting some Pile().

func (*WriterPile) Pile

func (d *WriterPile) Pile(item *bufio.Writer)

Pile appends an `*bufio.Writer` item to the WriterPile.

Note: Pile will block iff buff is exceeded and no Done() or Next()'s are used.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL