Search Apps Documentation Source Content File Folder Download Copy Actions Download

counter.gno

0.45 Kb ยท 23 lines
 1package governance
 2
 3// Counter manages unique incrementing IDs.
 4type Counter struct {
 5	id int64
 6}
 7
 8// NewCounter creates a new Counter starting at 0.
 9func NewCounter() *Counter {
10	return &Counter{
11		id: 0,
12	}
13}
14
15// Get returns the current ID without incrementing.
16func (c *Counter) Get() int64   { return c.id }
17func (c *Counter) Set(id int64) { c.id = id }
18
19// next increments and returns the next ID.
20func (c *Counter) Next() int64 {
21	c.id++
22	return c.id
23}