Debian Codegraph @

contrib/bug216610/go/fibber/fib.go

raw
1 // Package fibber implements a Fibonacci sequence generator using a C
2 // coded compute kernel (a .syso file).
3 package fibber
4
5 import (
6 "unsafe"
7 )
8
9 // State is the native Go form of the C.state structure.
10 type State struct {
11 B, A uint32
12 }
13
14 // cPtr converts State into a C pointer suitable as an argument for
15 // sysoCaller.
16 func (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.
22 func 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.
30 func (s *State) Next() {
31 syso__fib_next.call(s.cPtr())
32 }