Transaction

E0739A941FAFE1…DECFD851AC55

Block 25,648 · index 0 · indexed

Summary

Hash
E0739A941FAFE1C16D6F5DE482A188E4F79455B1BF80018A55EFDECFD851AC55
Block
25,648
Size
5450 bytes
Gas used
9,770,480 / 11,724,636
Fee
1000000ugnot
Memo
gnopublish
Status
success

Messages

#1AddPackagegno.land/p/moul/addrset/v19 arguments

Arguments · 9

  1. #1addrset
  2. #2README.md
  3. #3# `gno.land/p/moul/addrset/v1` A set of blockchain addresses, **backed by a B+ tree** (`gno.land/p/nt/bptree`). The B+ tree successor to [`p/moul/addrset/v0`](https://github.com/moul/gno-contracts/tree/main/p/moul/addrset/v0) (AVL-backed). **v1 because the backing data structure — and thus the on-chain storage layout — changed** (a compatibility change ⇒ new version). A B+ tree packs many entries per persisted node, so a stored address costs ~0.9 KB vs the AVL backing's ~2.0 KB, and inserts spend materially less gas — prefer v1 for persisted realm state. ```go import "gno.land/p/moul/addrset/v1" var set addrset.Set // zero value is an empty, usable set set.Add(addr) // true (newly added) set.Has(addr) // true set.Remove(addr) // true (was present) set.IterateByOffset(0, 10, func(a address) bool { return false }) ``` **Differences from v1:** the `Tree()` escape hatch is removed (the backing store never leaks); and — because the B+ tree mutates in place — do not Add/Remove from inside an iteration callback, and do not copy a non-zero `Set` by value. <!-- BEGIN GNOCONTRACTS FOOTER (generated by `make readmes`; do not edit below) --> --- Part of **[moul/gno-contracts](https://github.com/moul/gno-contracts)** — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage. **Dependency graph:** ![gno.land/p/moul/addrset/v1 dependency graph](https://raw.githubusercontent.com/moul/gno-contracts/main/_assets/gno.land/p/moul/addrset/v1/deps.png) Provenance: imported — see [https://github.com/moul/gno-contracts/pull/2](https://github.com/moul/gno-contracts/pull/2) for context and metadata. > ⚠️ **Disclaimer:** provided as-is, without warranty; not security-audited. Full disclaimer: [DISCLAIMER](https://github.com/moul/gno-contracts/blob/main/DISCLAIMER.md). <!-- END GNOCONTRACTS FOOTER -->
  4. #4addrset.gno
  5. #5// Package addrset provides a set of blockchain addresses, backed by a B+ tree. // // It is the B+ tree successor to [gno.land/p/moul/addrset/v0] (which is backed // by an AVL tree): a bump to v1 because the backing data structure — and thus // the on-chain storage layout — changed. The exported API is the same as v0 // (Add/Remove/Has/Size/IterateByOffset/ReverseIterateByOffset) EXCEPT that the // v0 `Tree() avl.ITree` escape hatch is intentionally removed, so the backing // store never leaks across realms. // // A B+ tree packs many entries per persisted node, so a stored address costs // roughly ~0.9 KB vs the AVL backing's ~2.0 KB (and inserts spend materially // less gas). Prefer v1 when the set is part of persisted realm state. // // Two behavioral differences from v0, both consequences of the in-place- // mutating B+ tree backing: // // - do NOT mutate the set (Add/Remove) from inside an iteration callback — // the AVL backing's copy-on-write tolerated it, this one does not; // - do NOT copy a non-zero Set by value — the copies would share live tree // nodes while their roots and sizes diverge (v0's copies were independent // snapshots). // // Example: // // var set addrset.Set // the zero value is an empty, usable set // // set.Add(addr) // true (newly added) // set.Has(addr) // true // set.Remove(addr) // true (was present) package addrset import "gno.land/p/nt/bptree/v0" // Set stores a set of addresses in sorted order. The zero value is an empty, // usable set. type Set struct { tree bptree.BPTree } // Add inserts an address into the set. // Returns true if the address was newly added, false if it already existed. func (s *Set) Add(addr address) bool { return !s.tree.Set(string(addr), nil) } // Remove deletes an address from the set. // Returns true if the address was found and removed, false if it didn't exist. func (s *Set) Remove(addr address) bool { _, removed := s.tree.Remove(string(addr)) return removed } // Has checks if an address exists in the set. func (s *Set) Has(addr address) bool { return s.tree.Has(string(addr)) } // Size returns the number of addresses in the set. func (s *Set) Size() int { return s.tree.Size() } // IterateByOffset walks through addresses in sorted order, starting at the // given offset and visiting up to count addresses. The callback returns true // to stop iteration. The set must not be modified during iteration. func (s *Set) IterateByOffset(offset int, count int, cb func(addr address) bool) { s.tree.IterateByOffset(offset, count, func(key string, _ any) bool { return cb(address(key)) }) } // ReverseIterateByOffset walks through addresses in reverse (descending) order, // starting at the given offset (counted from the end) and visiting up to count // addresses. The callback returns true to stop iteration. The set must not be // modified during iteration. func (s *Set) ReverseIterateByOffset(offset int, count int, cb func(addr address) bool) { s.tree.ReverseIterateByOffset(offset, count, func(key string, _ any) bool { return cb(address(key)) }) }
  6. #6gnomod.toml
  7. #7module = "gno.land/p/moul/addrset/v1" gno = "0.9"
  8. #8/gno.MemPackageType
  9. #9 MPUserProd

Result log

msg:0,success:true,log:,events:[]

← Back to block 25,648