// length of -1 means all
500163
func (s *storage) fetch(ctx context.Context, br blob.Ref, offset, length int64) (rc io.ReadCloser, size uint32, err error) {
	meta, err := s.meta(br)
	if err != nil {
		return nil, 0, err
	}

	if meta.file >= len(s.fds) {
		return nil, 0, fmt.Errorf("diskpacked: attempt to fetch blob from out of range pack file %d > %d", meta.file, len(s.fds))
	}
	rac := s.fds[meta.file]
	var rs io.ReadSeeker
	if length == -1 {
		// normal Fetch mode
		rs = io.NewSectionReader(rac, meta.offset, int64(meta.size))
	} else {
		if offset > int64(meta.size) {
			return nil, 0, blob.ErrOutOfRangeOffsetSubFetch
		} else if offset+length > int64(meta.size) {
			length = int64(meta.size) - offset
		}
		rs = io.NewSectionReader(rac, meta.offset+offset, length)
	}
	fn := rac.Name()
	// Ensure entry is in map.
	readVar.Add(fn, 0)
	if v, ok := readVar.Get(fn).(*expvar.Int); ok {
		rs = readerutil.NewStatsReadSeeker(v, rs)
	}
	readTotVar.Add(s.root, 0)
	if v, ok := readTotVar.Get(s.root).(*expvar.Int); ok {
		rs = readerutil.NewStatsReadSeeker(v, rs)
	}
	rsc := struct {
		io.ReadSeeker
		io.Closer
	}{
		rs,
		types.NopCloser,
	}
	return rsc, meta.size, nil
}
1231729
func (rd *RAMDirectory) FileLength(name string) (length int64, err error) {
	rd.EnsureOpen()
	rd.fileMapLock.RLock()
	defer rd.fileMapLock.RUnlock()
	if file, ok := rd.fileMap[name]; ok {
		return file.Length(), nil
	}
	return 0, os.ErrNotExist
}
1090891
func (a *Array) Length() *Number {
	return &Number{a.chain, float64(len(a.value))}
}
195841
func (vec *T) LengthSqr() float64 {
	return vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2]
}
435173
func (i Interval) Length() float64 {
	l := i.Hi - i.Lo
	if l >= 0 {
		return l
	}
	l += 2 * math.Pi
	if l > 0 {
		return l
	}
	return -1
}
259533
func (lru *LRUCache) Length() int64 {
	lru.mu.Lock()
	defer lru.mu.Unlock()
	return int64(lru.list.Len())
}
1295853
func (m *mapReact) Length() int {
	var l int
	m.ro.RLock()
	l = len(m.ma)
	m.ro.RUnlock()
	return l
}
1367366
func (ds *DefaultSimilarity) lengthNorm(state *index.FieldInvertState) float32 {
	var numTerms int
	if ds.discountOverlaps {
		numTerms = state.Length() - state.NumOverlap()
	} else {
		numTerms = state.Length()
	}
	return state.Boost() * float32(1.0/math.Sqrt(float64(numTerms)))
}
1209447
func (g *LineString) Length() float64 {
	return length1(g.flatCoords, 0, len(g.flatCoords), g.stride)
}
180907
func (b *Buffer) Length() int {
	if b == nil || b.C_gss_buffer_t == nil || b.C_gss_buffer_t.length == 0 {
		return 0
	}
	return int(b.C_gss_buffer_t.length)
}
563826
func (aa *AtomicArray) Length() int {
	aa.mutex.RLock()
	res := aa.length
	aa.mutex.RUnlock()

	return res
}
1344169
func (s *OIDSet) Length() int {
	if s == nil {
		return 0
	}
	return int(s.C_gss_OID_set.count)
}
598975
func (f *Footer) Length() uint64 {
	jBuf, err := json.Marshal(f)
	if err != nil {
		return 0
	}

	footerLen := footerBegLen + len(jBuf) + footerEndLen
	return uint64(footerLen)
}
30728
func (self *Collection) LengthAttribute() IntegerAttribute {
	result := &computedLength{
		NewAttribute(VALUE_ONLY, self.length, nil), self,
	}
	return result
}
546474
func Length(p0, p1, p2 *vec2.T, t float64) float64 {
	ax := p0[0] - 2*p1[0] + p2[0]
	ay := p0[1] - 2*p1[1] + p2[1]
	bx := 2*p1[0] - 2*p0[0]
	by := 2*p1[1] - 2*p0[1]

	a := 4 * (ax*ax + ay*ay)
	b := 4 * (ax*bx + ay*by)
	c := bx*bx + by*by

	abc := 2 * math.Sqrt(a+b+c)
	a2 := math.Sqrt(a)
	a32 := 2 * a * a2
	c2 := 2 * math.Sqrt(c)
	ba := b / a2

	return t * (a32*abc + a2*b*(abc-c2) + (4*c*a-b*b)*math.Log((2*a2+ba+abc)/(ba+c2))) / (4 * a32)
}
966528
func (pc PrefixCodes) checkLengths() bool {
	sum := 1 << valueBits
	for _, c := range pc {
		sum -= (1 << valueBits) >> uint(c.Len)
	}
	return sum == 0 || len(pc) == 0
}
544878
func Length(g orb.Geometry, df orb.DistanceFunc) float64 {
	if g == nil {
		return 0
	}

	switch g := g.(type) {
	case orb.Point:
		return 0
	case orb.MultiPoint:
		return 0
	case orb.LineString:
		return lineStringLength(g, df)
	case orb.MultiLineString:
		sum := 0.0
		for _, ls := range g {
			sum += lineStringLength(ls, df)
		}

		return sum
	case orb.Ring:
		return lineStringLength(orb.LineString(g), df)
	case orb.Polygon:
		return polygonLength(g, df)
	case orb.MultiPolygon:
		sum := 0.0
		for _, p := range g {
			sum += polygonLength(p, df)
		}

		return sum
	case orb.Collection:
		sum := 0.0
		for _, c := range g {
			sum += Length(c, df)
		}

		return sum
	case orb.Bound:
		return Length(g.ToRing(), df)
	}

	panic(fmt.Sprintf("geometry type not supported: %T", g))
}