xref: /aosp_15_r20/external/libcap/contrib/bug216610/go/fibber/fib.go (revision 2810ac1b38eead2603277920c78344c84ddf3aff)
1// Package fibber implements a Fibonacci sequence generator using a C
2// coded compute kernel (a .syso file).
3package fibber
4
5import (
6	"unsafe"
7)
8
9// State is the native Go form of the C.state structure.
10type State struct {
11	B, A uint32
12}
13
14// cPtr converts State into a C pointer suitable as an argument for
15// sysoCaller.
16func (s *State) cPtr() unsafe.Pointer {
17	return unsafe.Pointer(&s.B)
18}
19
20// NewState initializes a Fibonacci Number sequence generator.  Upon
21// return s.A=0 and s.B=1 are the first two numbers in the sequence.
22func NewState() *State {
23	s := &State{}
24	syso__fib_init.call(s.cPtr())
25	return s
26}
27
28// Next advances the state to the next number in the sequence. Upon
29// return, s.B is the most recently calculated value.
30func (s *State) Next() {
31	syso__fib_next.call(s.cPtr())
32}
33