podman
1// Copyright 2018 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// Package set provides simple set data structures for uint64s.
6package set7
8import "math/bits"9
10// int64s represents a set of integers within the range of 0..63.
11type int64s uint6412
13func (bs *int64s) Len() int {14return bits.OnesCount64(uint64(*bs))15}
16func (bs *int64s) Has(n uint64) bool {17return uint64(*bs)&(uint64(1)<<n) > 018}
19func (bs *int64s) Set(n uint64) {20*(*uint64)(bs) |= uint64(1) << n21}
22func (bs *int64s) Clear(n uint64) {23*(*uint64)(bs) &^= uint64(1) << n24}
25
26// Ints represents a set of integers within the range of 0..math.MaxUint64.
27type Ints struct {28lo int64s
29hi map[uint64]struct{}30}
31
32func (bs *Ints) Len() int {33return bs.lo.Len() + len(bs.hi)34}
35func (bs *Ints) Has(n uint64) bool {36if n < 64 {37return bs.lo.Has(n)38}39_, ok := bs.hi[n]40return ok41}
42func (bs *Ints) Set(n uint64) {43if n < 64 {44bs.lo.Set(n)45return46}47if bs.hi == nil {48bs.hi = make(map[uint64]struct{})49}50bs.hi[n] = struct{}{}51}
52func (bs *Ints) Clear(n uint64) {53if n < 64 {54bs.lo.Clear(n)55return56}57delete(bs.hi, n)58}
59