README.md
0.87 Kb ยท 36 lines
1# seqid
2
3```
4package seqid // import "gno.land/p/demo/seqid"
5
6Package seqid provides a simple way to have sequential IDs which will be ordered
7correctly when inserted in an AVL tree.
8
9Sample usage:
10
11 var id seqid.ID
12 var users avl.Tree
13
14 func NewUser() {
15 users.Set(id.Next().Binary(), &User{ ... })
16 }
17
18TYPES
19
20type ID uint64
21 An ID is a simple sequential ID generator.
22
23func FromBinary(b string) (ID, bool)
24 FromBinary creates a new ID from the given string.
25
26func (i ID) Binary() string
27 Binary returns a big-endian binary representation of the ID, suitable to be
28 used as an AVL key.
29
30func (i *ID) Next() ID
31 Next advances the ID i. It will panic if increasing ID would overflow.
32
33func (i *ID) TryNext() (ID, bool)
34 TryNext increases i by 1 and returns its value. It returns true if
35 successful, or false if the increment would result in an overflow.
36```