Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

addrset source pure

Package addrset provides a specialized set data structure for managing unique Gno addresses.

Overview

Package addrset provides a specialized set data structure for managing unique Gno addresses.

It is built on top of an AVL tree for efficient operations and maintains addresses in sorted order. This package is particularly useful when you need to:

  • Track a collection of unique addresses (e.g., for whitelists, participants, etc.)
  • Efficiently check address membership
  • Support pagination when displaying addresses

Example usage:

Example
 1import (
 2    "gno.land/p/moul/addrset"
 3)
 4
 5func MyHandler() {
 6    // Create a new address set
 7    var set addrset.Set
 8
 9    // Add some addresses
10    addr1 := address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
11    addr2 := address("g1sss5g0rkqr88k4u648yd5d3l9t4d8vvqwszqth")
12
13    set.Add(addr1)  // returns true (newly added)
14    set.Add(addr2)  // returns true (newly added)
15    set.Add(addr1)  // returns false (already exists)
16
17    // Check membership
18    if set.Has(addr1) {
19        // addr1 is in the set
20    }
21
22    // Get size
23    size := set.Size()  // returns 2
24
25    // Iterate with pagination (10 items per page, starting at offset 0)
26    set.IterateByOffset(0, 10, func(addr address) bool {
27        // Process addr
28        return false  // continue iteration
29    })
30
31    // Remove an address
32    set.Remove(addr1)  // returns true (was present)
33    set.Remove(addr1)  // returns false (not present)
34}

Types 1

type Set

struct
1type Set struct {
2	tree avl.Tree
3}
source

Methods on Set

func Add

method on Set
1func (s *Set) Add(addr address) bool
source

Add inserts an address into the set. Returns true if the address was newly added, false if it already existed.

func Has

method on Set
1func (s *Set) Has(addr address) bool
source

Has checks if an address exists in the set.

func IterateByOffset

method on Set
1func (s *Set) IterateByOffset(offset int, count int, cb func(addr address) bool)
source

IterateByOffset walks through addresses starting at the given offset. The callback should return true to stop iteration.

func Remove

method on Set
1func (s *Set) Remove(addr address) bool
source

Remove deletes an address from the set. Returns true if the address was found and removed, false if it didn't exist.

func ReverseIterateByOffset

method on Set
1func (s *Set) ReverseIterateByOffset(offset int, count int, cb func(addr address) bool)
source

ReverseIterateByOffset walks through addresses in reverse order starting at the given offset. The callback should return true to stop iteration.

func Size

method on Set
1func (s *Set) Size() int
source

Size returns the number of addresses in the set.

func Tree

method on Set
1func (s *Set) Tree() avl.ITree
source

Tree returns the underlying AVL tree for advanced usage.

Imports 1

Source Files 3