Documentation ¶
Overview ¶
Package protohackers provides several useful utility functions which can be used while solving problems on protohackers.com.
Index ¶
- func ListenAcceptAndHandleParallel(network, address string, handler ConnHandler) error
- func ListenAcceptAndHandleParallelStateful[State any](network, address string, initialState func() State, ...) error
- type BytesHandler
- type BytesHandlerStateful
- type ConnHandler
- func ByteConnHandler(handler BytesHandler) ConnHandler
- func LineConnHandler(handler BytesHandler) ConnHandler
- func NBytesConnHandler(n int64, handler BytesHandler) ConnHandler
- func SplitFuncConnHandler(inputSplitter bufio.SplitFunc, responseDelimiter []byte, handler BytesHandler) ConnHandler
- func WordConnHandler(handler BytesHandler) ConnHandler
- type ConnHandlerStateful
- func ByteConnHandlerStateful[State any](handler BytesHandlerStateful[State]) ConnHandlerStateful[State]
- func LineConnHandlerStateful[State any](handler BytesHandlerStateful[State]) ConnHandlerStateful[State]
- func NBytesConnHandlerStateful[State any](n int64, handler BytesHandlerStateful[State]) ConnHandlerStateful[State]
- func SplitFuncConnHandlerStateful[State any](inputSplitter bufio.SplitFunc, responseDelimiter []byte, ...) ConnHandlerStateful[State]
- func WordConnHandlerStateful[State any](handler BytesHandlerStateful[State]) ConnHandlerStateful[State]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAcceptAndHandleParallel ¶
func ListenAcceptAndHandleParallel(network, address string, handler ConnHandler) error
ListenAcceptAndHandleParallel listens on the given network and address, accepts an unlimited amount of connections in parallel from the given listener, calling the given handler in a goroutine for each connection.
func ListenAcceptAndHandleParallelStateful ¶
func ListenAcceptAndHandleParallelStateful[State any](network, address string, initialState func() State, handler ConnHandlerStateful[State]) error
ListenAcceptAndHandleParallelStateful is like ListenAcceptAndHandleParallel, but allows the caller to handle per-connection state of type State.
Types ¶
type BytesHandler ¶
type BytesHandlerStateful ¶
type ConnHandler ¶
func ByteConnHandler ¶
func ByteConnHandler(handler BytesHandler) ConnHandler
ByteConnHandler returns a connection handler that will continually:
- read a byte
- call the given handler function with that byte
- if the handler function returns a non-nil pointer to a byte slice, write it to the connection
func LineConnHandler ¶
func LineConnHandler(handler BytesHandler) ConnHandler
LineConnHandler returns a connection handler that will continually:
- read a line of bytes (a sequence of bytes ending in a newline character)
- call the given handler function with those bytes
- if the handler function returns a non-nil pointer to a byte slice, write it to the connection, followed by a newline (otherwise do nothing).
Lines passed to the handler do not contain newlines.
func NBytesConnHandler ¶
func NBytesConnHandler(n int64, handler BytesHandler) ConnHandler
NBytesConnHandler returns a connection handler that will continually:
- read at most n bytes
- call the given handler function with those bytes
- if the handler function returns a non-nil pointer to a byte slice, write it to the connection
func SplitFuncConnHandler ¶
func SplitFuncConnHandler(inputSplitter bufio.SplitFunc, responseDelimiter []byte, handler BytesHandler) ConnHandler
SplitFuncConnHandler returns a connection handler that will continually:
- read a sequence of bytes, delimited as defined by the given bufio.SplitFunc
- call the given handler function with those bytes
- if the handler function returns a non-nil pointer to a byte slice, write it to the connection, followed by responseDelimiter
func WordConnHandler ¶
func WordConnHandler(handler BytesHandler) ConnHandler
WordConnHandler returns a connection handler that will continually:
- read a word of bytes (as defined by bufio.ScanWords)
- call the given handler function with those bytes
- if the handler function returns a non-nil pointer to a byte slice, write it to the connection, followed by a space (otherwise do nothing).
Lines passed to the handler do not contain spaces.
type ConnHandlerStateful ¶
func ByteConnHandlerStateful ¶
func ByteConnHandlerStateful[State any](handler BytesHandlerStateful[State]) ConnHandlerStateful[State]
ByteConnHandlerStateful is a stateful version of ByteWordConnHandler
func LineConnHandlerStateful ¶
func LineConnHandlerStateful[State any](handler BytesHandlerStateful[State]) ConnHandlerStateful[State]
LineConnHandlerStateful is a stateful version of LineConnHandler
func NBytesConnHandlerStateful ¶
func NBytesConnHandlerStateful[State any](n int64, handler BytesHandlerStateful[State]) ConnHandlerStateful[State]
NBytesConnHandlerStateful is a stateful version of NBytesConnHandler
func SplitFuncConnHandlerStateful ¶
func SplitFuncConnHandlerStateful[State any](inputSplitter bufio.SplitFunc, responseDelimiter []byte, handler BytesHandlerStateful[State]) ConnHandlerStateful[State]
SplitFuncConnHandler returns a connection handler that will continually:
- read a sequence of bytes, delimited as defined by the given bufio.SplitFunc
- call the given handler function with those bytes
- if the handler function returns a non-nil pointer to a byte slice, write it to the connection, followed by responseDelimiter
func WordConnHandlerStateful ¶
func WordConnHandlerStateful[State any](handler BytesHandlerStateful[State]) ConnHandlerStateful[State]
WordConnHandlerStateful is a stateful version of WordConnHandler
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
0
Solution to problem 0: [Smoke Test]
|
Solution to problem 0: [Smoke Test] |
1
Solution to problem 1: Prime Time
[Prime Time]: https://protohackers.com/problem/1
|
Solution to problem 1: Prime Time [Prime Time]: https://protohackers.com/problem/1 |
2
Solution to problem 2: Means to an End
[Means to an End]: https://protohackers.com/problem/2
|
Solution to problem 2: Means to an End [Means to an End]: https://protohackers.com/problem/2 |
3
Solution to problem 3: Budget Chat
[Budget Chat]: https://protohackers.com/problem/3
|
Solution to problem 3: Budget Chat [Budget Chat]: https://protohackers.com/problem/3 |