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

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

/p/g17khqpukees4237dtn3astzapmp462vjhsz6st4/bitset

Directory · 3 Files
README.md Open

Bitset Package

Package implements an arbitrary-size bit set, also known as bit array.

Bit sets are useful when you need a compact way to track large sets of boolean flags, such as permissions, feature toggles, or membership sets, using significantly less memory than a slice of booleans while also supporting fast bulk operations across entire sets.

Repository can be found at jeronimoalbi/gnome, as part of jeronimoalbi's Gno smart contracts monorepo.

Usage

 1package main
 2
 3import "gno.land/p/g17khqpukees4237dtn3astzapmp462vjhsz6st4/bitset"
 4
 5const (
 6	PermRead   = 0
 7	PermWrite  = 1
 8	PermDelete = 2
 9	PermAdmin  = 3
10)
11
12func main() {
13	var perms bitset.BitSet
14	perms.Set(PermRead)
15	perms.Set(PermWrite)
16
17	println("Can read:", perms.IsSet(PermRead))
18	println("Can write:", perms.IsSet(PermWrite))
19	println("Can delete:", perms.IsSet(PermDelete))
20	println("Is admin:", perms.IsSet(PermAdmin))
21	println("Permissions set:", perms.Len())
22}
23
24// Output:
25// Can read: true
26// Can write: true
27// Can delete: false
28// Is admin: false
29// Permissions set: 2