func (p *Prefix) NumNodes() *big.Int {
	i := new(big.Int).SetBytes(invert(p.Mask))
	return i.Add(i, big.NewInt(1))
}
NumNodes returns the number of IP node addresses in p.
package ipaddr
import (
	"encoding"
	"encoding/binary"
	"fmt"
	"math"
	"math/big"
	"math/bits"
	"net"
)
var (
	_ encoding.BinaryMarshaler   = &Prefix{}
	_ encoding.BinaryUnmarshaler = &Prefix{}
	_ encoding.TextMarshaler     = &Prefix{}
	_ encoding.TextUnmarshaler   = &Prefix{}
	_ fmt.Stringer = &Prefix{}
)
const (
	IPv4PrefixLen = 8 * net.IPv4len  
	IPv6PrefixLen = 8 * net.IPv6len  
)
type Prefix struct {
	net.IPNet
}
func (p *Prefix) lastIPv4Int() ipv4Int {
	return ipToIPv4Int(p.IP) | ipv4Int(^mask32(p.Len()))
}
func (p *Prefix) lastIPv4MappedIPv6Int() ipv6Int {
	i4 := ipToIPv4Int(p.IP) | ipv4Int(^mask32(p.Len()))
	var i6 ipv6Int
	i6[1] = 0x0000ffff00000000 | uint64(i4)
	return i6
}
func (p *Prefix) lastIPv6Int() ipv6Int {
	i := ipToIPv6Int(p.IP)
	var m ipv6Int
	m.invmask(p.Len())
	i[0], i[1] = i[0]|m[0], i[1]|m[1]
	return i
}
func (p *Prefix) Contains(q *Prefix) bool {
	if p.IP.To4() != nil {
		return p.containsIPv4(q)
	}
	if p.IP.To16() != nil && p.IP.To4() == nil {
		return p.containsIPv6(q)
	}
	return false
}
func (p *Prefix) containsIPv4(q *Prefix) bool {
	if q.IP.To4() == nil {
		return false
	}
	l := p.Len()
	if l >= q.Len() {
		return false
	}
	base := ipToIPv4Int(p.IP.Mask(p.Mask))
	mask := ipMaskToIPv4Int(p.Mask)
	fip := ipToIPv4Int(q.IP)
	lip := q.lastIPv4Int()
	fdiff := uint32((base ^ fip) & mask)
	ldiff := uint32((base ^ lip) & mask)
	return bits.LeadingZeros32(fdiff) >= l && bits.LeadingZeros32(ldiff) >= l
}
func (p *Prefix) containsIPv6(q *Prefix) bool {
	if q.IP.To16() == nil || q.IP.To4() != nil {
		return false
	}
	l := p.Len()
	if l >= q.Len() {
		return false
	}
	base := ipToIPv6Int(p.IP)
	mask := ipMaskToIPv6Int(p.Mask)
	l0, l1 := 64, l-64
	if l < 64 {
		l0, l1 = l, 0
	}
	fip := ipToIPv6Int(q.IP)
	lip := q.lastIPv6Int()
	var fdiff, ldiff ipv6Int
	fdiff[0], fdiff[1] = (base[0]^fip[0])&mask[0], (base[1]^fip[1])&mask[1]
	ldiff[0], ldiff[1] = (base[0]^lip[0])&mask[0], (base[1]^lip[1])&mask[1]
	return bits.LeadingZeros64(fdiff[0]) >= l0 && bits.LeadingZeros64(fdiff[1]) >= l1 && bits.LeadingZeros64(ldiff[0]) >= l0 && bits.LeadingZeros64(ldiff[1]) >= l1
}
func (p *Prefix) Equal(q *Prefix) bool {
	return compareAscending(p, q) == 0
}
func (p *Prefix) Exclude(q *Prefix) []Prefix {
	if !p.IPNet.Contains(q.IP) {
		return nil
	}
	if p.Equal(q) {
		return []Prefix{*q}
	}
	subsFn := subnetsIPv6
	if p.IP.To4() != nil {
		subsFn = subnetsIPv4
	}
	var ps []Prefix
	l, r := subsFn(p, false)
	for !l.Equal(q) && !r.Equal(q) {
		if l.IPNet.Contains(q.IP) {
			ps = append(ps, *r)
			l, r = subsFn(l, true)
		} else if r.IPNet.Contains(q.IP) {
			ps = append(ps, *l)
			l, r = subsFn(r, true)
		}
	}
	if l.Equal(q) {
		ps = append(ps, *r)
	} else if r.Equal(q) {
		ps = append(ps, *l)
	}
	return ps
}
func subnetsIPv4(p *Prefix, reuse bool) (l *Prefix, r *Prefix) {
	i := ipToIPv4Int(p.IP) | ipv4Int(1<<uint(IPv4PrefixLen-p.Len()-1))
	r = i.prefix(p.Len()+1, IPv4PrefixLen)
	if reuse {
		l = p
		binary.BigEndian.PutUint32(l.Mask, mask32(l.Len()+1))
	} else {
		l = ipToIPv4Int(p.IP).prefix(p.Len()+1, IPv4PrefixLen)
	}
	return
}
func subnetsIPv6(p *Prefix, reuse bool) (l *Prefix, r *Prefix) {
	i := ipToIPv6Int(p.IP)
	id := ipv6Int{0, 1}
	id.lsh(IPv6PrefixLen - p.Len() - 1)
	ii := ipv6Int{i[0] | id[0], i[1] | id[1]}
	r = ii.prefix(p.Len()+1, IPv6PrefixLen)
	if reuse {
		l = p
		var m ipv6Int
		m.mask(l.Len() + 1)
		binary.BigEndian.PutUint64(l.Mask[:8], m[0])
		binary.BigEndian.PutUint64(l.Mask[8:16], m[1])
	} else {
		l = i.prefix(p.Len()+1, IPv6PrefixLen)
	}
	return
}
func (p *Prefix) Hostmask() net.IPMask {
	return invert(p.Mask)
}
func (p *Prefix) Last() net.IP {
	if p.IP.To4() != nil {
		i := p.lastIPv4Int()
		return i.ip()
	}
	if p.IP.To16() != nil && p.IP.To4() == nil {
		i := p.lastIPv6Int()
		return i.ip()
	}
	return nil
}
func (p *Prefix) Len() int {
	l, _ := p.Mask.Size()
	return l
}
func (p *Prefix) MarshalBinary() ([]byte, error) {
	ip := p.IP
	if p.IP.To4() != nil {
		ip = p.IP.To4()
	}
	var b [1 + net.IPv6len]byte
	n := p.Len()
	l := ((n + 8 - 1) &^ (8 - 1)) / 8
	b[0] = byte(n)
	l++
	copy(b[1:l], ip)
	return b[:l], nil
}
func (p *Prefix) MarshalText() ([]byte, error) {
	return []byte(p.String()), nil
}