github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/p/demo/seqid/README.md (about) 1 # seqid 2 3 ``` 4 package seqid // import "gno.land/p/demo/seqid" 5 6 Package seqid provides a simple way to have sequential IDs which will be ordered 7 correctly when inserted in an AVL tree. 8 9 Sample 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 18 TYPES 19 20 type ID uint64 21 An ID is a simple sequential ID generator. 22 23 func FromBinary(b string) (ID, bool) 24 FromBinary creates a new ID from the given string. 25 26 func (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 30 func (i *ID) Next() ID 31 Next advances the ID i. It will panic if increasing ID would overflow. 32 33 func (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 ```