// calculateIPOffset calculates the integer offset of ip from base such that
// base + offset = ip. It requires ip >= base.
167056
func calculateIPOffset(base *big.Int, ip net.IP) int {
	return int(big.NewInt(0).Sub(bigForIP(ip), base).Int64())
}
756160
func (q *Query) Offset(amount uint) *Query {
	q.query.Offset(amount)
	return q
}
1031260
func (p *PdfDictionaryObj) GetOffset(glyph int) int {
	ttfp := p.PtrToSubsetFontObj.GetTTFParser()
	glyf := ttfp.GetTables()["glyf"]
	offset := int(glyf.Offset + ttfp.LocaTable[glyph])
	return offset
}
1172897
func (a *IPRangeAllocator) Subtract(iprange *IPRange) {
	curBig := big.NewInt(0)
	curBig.SetBytes(iprange.Start)
	endBig := big.NewInt(0)
	endBig.SetBytes(iprange.End)

	for ; curBig.Cmp(endBig) < 1; curBig = curBig.Add(big.NewInt(1), curBig) {
		ip := a.bigIntToIP(curBig)
		if a.ipRange.Contains(ip) {
			a.Reserve(ip)
		}
	}
}
6199
func DecimalToIPv4(addr uint32) net.IP {
	bytes := make([]byte, 4)
	binary.BigEndian.PutUint32(bytes, addr)
	return net.IP(bytes)
}
685852
func GetPingOffset(beacon time.Duration, devAddr lorawan.DevAddr, pingNb int) (int, error) {
	if pingNb == 0 {
		return 0, errors.New("pingNb must be > 0")
	}

	if beacon%beaconPeriod != 0 {
		return 0, fmt.Errorf("beacon must be a multiple of %s", beaconPeriod)
	}

	devAddrBytes, err := devAddr.MarshalBinary()
	if err != nil {
		return 0, errors.Wrap(err, "marshal devaddr error")
	}

	pingPeriod := pingPeriodBase / pingNb
	beaconTime := uint32(int64(beacon/time.Second) % (1 << 32))

	key := lorawan.AES128Key{} // 16 x 0x00
	block, err := aes.NewCipher(key[:])
	if err != nil {
		return 0, errors.Wrap(err, "new cipher error")
	}

	if block.BlockSize() != 16 {
		return 0, errors.New("block size of 16 was expected")
	}

	b := make([]byte, len(key))
	rand := make([]byte, len(key))

	binary.LittleEndian.PutUint32(b[0:4], beaconTime)
	copy(b[4:8], devAddrBytes)
	block.Encrypt(rand, b)

	return (int(rand[0]) + int(rand[1])*256) % pingPeriod, nil
}
885517
func (this *SiestaClient) GetOffset(group string, topic string, partition int32) (int64, error) {
	offset, err := this.connector.GetOffset(group, topic, partition)
	if err == siesta.ErrUnknownTopicOrPartition {
		return -1, nil
	}
	return offset, err
}
11357
func (ic *IngressIPController) allocateIP(requestedIP string) (net.IP, error) {
	if len(requestedIP) == 0 {
		// Specific ip not requested
		return ic.ipAllocator.AllocateNext()
	}
	var ip net.IP
	if ip = net.ParseIP(requestedIP); ip == nil {
		// Invalid ip
		return ic.ipAllocator.AllocateNext()
	}
	if err := ic.ipAllocator.Allocate(ip); err != nil {
		// Unable to allocate requested ip
		return ic.ipAllocator.AllocateNext()
	}
	// Allocated requested ip
	return ip, nil
}
594361
func (gi *GeoIP) lookupByIPNum(ip uint32) int {
	buf := make([]byte, 2*maxRecordLength)
	x := make([]int, 2)
	offset := 0
	for depth := 31; depth >= 0; depth-- {
		for i := 0; i < 2*maxRecordLength; i++ {
			buf[i] = gi.data[(2*gi.recordLength*offset)+i]
		}
		for i := 0; i < 2; i++ {
			x[i] = 0
			for j := 0; j < gi.recordLength; j++ {
				var y int = int(buf[i*gi.recordLength+j])
				if y < 0 {
					y += 256
				}
				x[i] += (y << uint(j*8))
			}
		}
		if (ip & (1 << uint(depth))) > 0 {
			if x[1] >= gi.databaseSegment {
				return x[1]
			}
			offset = x[1]
		} else {
			if x[0] >= gi.databaseSegment {
				return x[0]
			}
			offset = x[0]
		}
	}
	return 0
}
981494
func (o *Object) setOffset(bytesRead int64) error {
	// Update the currentOffset.
	o.currOffset += bytesRead

	if o.objectInfo.Size > -1 && o.currOffset >= o.objectInfo.Size {
		return io.EOF
	}
	return nil
}
394151
func posFromOffset(offset int, source []byte) (int, int, string) {
	if source == nil {
		return 0, 0, ""
	}
	return util.Highlight(source, int64(offset))
}
1154014
func (s *CreateIPSetOutput) SetIPSet(v *IPSet) *CreateIPSetOutput {
	s.IPSet = v
	return s
}
1123715
func IntToIP4(n uint32) net.IP {
	ip := make([]byte, 4)
	binary.BigEndian.PutUint32(ip, n)
	return ip
}
309425
func (pq *PriorityQueue) findOffset(offset uint64) (*PriorityItem, error) {
	var length uint64
	var curLevel uint8 = pq.curLevel
	var newLevel int

	// Handle newLevel initialization for descending order.
	if pq.order == DESC {
		newLevel = 255
	}

	// For condition expression.
	condExpr := func(level int) bool {
		if pq.order == ASC {
			return level <= 255
		}
		return level >= 0
	}

	// For loop expression.
	loopExpr := func(level *int) {
		if pq.order == ASC {
			*level++
		} else if pq.order == DESC {
			*level--
		}
	}

	// Level comparison.
	cmpLevels := func(newLevel, curLevel uint8) bool {
		if pq.order == ASC {
			return newLevel >= curLevel
		}
		return newLevel <= curLevel
	}

	// Loop through the priority levels.
	for ; condExpr(newLevel); loopExpr(&newLevel) {
		// If this level is lower than the current level based on ordering and contains items.
		if cmpLevels(uint8(newLevel), curLevel) && pq.levels[uint8(newLevel)].length() > 0 {
			curLevel = uint8(newLevel)
			newLength := pq.levels[curLevel].length()

			// If the offset is within the current priority level.
			if length+newLength >= offset+1 {
				return pq.getItemByPriorityID(curLevel, offset-length+1)
			}

			length += newLength
		}
	}

	return nil, ErrOutOfBounds
}
538680
func (p pointer) offset(f field) pointer {
	return pointer{v: p.v.Elem().FieldByIndex(f).Addr()}
}
262304
func randomOffset(n int) int {
	if n == 0 {
		return 0
	}

	val, err := rand.Int(rand.Reader, big.NewInt(int64(n)))
	if err != nil {
		logrus.Errorf("Failed to get a random offset: %v", err)
		return 0
	}

	return int(val.Int64())
}
1265290
func IPRange(start, stop net.IP) int {
	return int(binary.BigEndian.Uint32(stop.To4())) - int(binary.BigEndian.Uint32(start.To4())) + 1
}