github.com/cilium/cilium@v1.16.2/pkg/ipam/service/allocator/utils.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  // Copyright The Kubernetes Authors.
     4  
     5  package allocator
     6  
     7  import (
     8  	"math/big"
     9  	"math/bits"
    10  )
    11  
    12  // countBits returns the number of set bits in n
    13  func countBits(n *big.Int) int {
    14  	var count int = 0
    15  	for _, w := range n.Bits() {
    16  		count += bits.OnesCount64(uint64(w))
    17  	}
    18  	return count
    19  }