1package boards23// PermissionSet defines a type to store any number of permissions.4type PermissionSet []uint6456// NewPermissionSet creates a new PermissionSet containing the given permissions.7func NewPermissionSet(perms ...Permission) PermissionSet {8 if len(perms) == 0 {9 return nil10 }1112 // Find max permission value to calculate slice size.13 // This allows any number of permissions to be assigned in any order.14 var max Permission15 for _, p := range perms {16 if p > max {17 max = p18 }19 }2021 s := make(PermissionSet, int(max)/64+1)22 for _, p := range perms {23 // Calculate the index within the set where the permission should be defined.24 // Each item in the set can contain 64 permissions, for example:25 // - Item 0: permissions 0 to 6326 // - Item 1: permissions 64 to 12727 idx := int(p) / 642829 // Turn on the bit that matches the permission, ranging from bit 0 to 6330 s[idx] |= 1 << (uint(p) % 64)31 }32 return s33}3435// Has checks if a permission is in the set.36func (s PermissionSet) Has(p Permission) bool {37 idx := int(p) / 6438 if idx >= len(s) {39 return false40 }4142 // Check if the bit for the current permission is on43 return s[idx]&(1<<(uint(p)%64)) != 044}4546// IsEmpty reports whether the set contains no permissions.47func (s PermissionSet) IsEmpty() bool {48 for _, v := range s {49 if v != 0 {50 return false51 }52 }53 return true54}55Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.