Exemplo n.º 1
0
Arquivo: stack.go Projeto: vgp/gogp
func (s *stack) Write(bytes []byte) (n int, err error) {
	// Write the given bytes into the stack such that the first byte is on
	// the top of the stack
	(*s) = append(*s, bytes...)
	vbytes.Reverse((*s)[len(*s)-len(bytes):])
	return len(bytes), nil
}
Exemplo n.º 2
0
Arquivo: stack.go Projeto: vgp/gogp
func (s *stack) Read(bytes []byte) (n int, err error) {
	// Read back bytes from the stack such that the first byte read is from
	// the top of the stack
	to_read := len(bytes)
	if to_read > len(*s) {
		to_read = len(*s)
	}
	copy(bytes, (*s)[len(*s)-to_read:])
	*s = (*s)[:len(*s)-to_read]
	vbytes.Reverse(bytes)
	return
}