// StringAt : utility function to get a ChunkString object at a given offset
// @reader : reader containing ChunkString struct @ offset
// @offset : offset at which we find the ChunkString
// return ChunkString
559669
func StringAt(reader io.ReadSeeker, offset int64) (cs ChunkString, err error) {
	// Backup offset
	backup := BackupSeeker(reader)
	// Offsets are relative to start of chunk
	GoToSeeker(reader, offset)
	err = cs.Parse(reader)
	/*if err != nil {
		return
	}*/
	GoToSeeker(reader, backup)
	return
}
722693
func (db *RedisDB) stringGet(k string) string {
	if t, ok := db.keys[k]; !ok || t != "string" {
		return ""
	}
	return db.stringKeys[k]
}
842185
func (wpr *Wrapper) WriteAt(p []byte, off int64) (n int, err error) {
	wrap := NewWrapWriter(wpr.rwa, wpr.O+off, wpr.N)
	w := limio.LimitWriter(wrap, wpr.N-off)
	n, err = w.Write(p)
	if wpr.L < off+int64(n) {
		wpr.L = int64(n) + off
	}
	return n, err
}
404247
func (wpr *Wrapper) ReadAt(p []byte, off int64) (n int, err error) {
	wrap := NewWrapReader(wpr.rwa, wpr.O+off, wpr.N)
	r := io.LimitReader(wrap, wpr.L-off)
	return r.Read(p)
}
614158
func (lir *LookupInResult) ContentAt(idx int, valuePtr interface{}) error {
	if idx > len(lir.contents) {
		return errors.New("the supplied index was invalid")
	}
	return lir.contents[idx].as(valuePtr, JSONDecode)
}
1286896
func (f *File) ReadAt(p []byte, off int64) (n int, err error) {
	// ReadAt doesn't affect the underlying offset.
	readBytes, err := f.fs.config.KBFSOps().Read(f.fs.ctx, f.node, p, off)
	if err != nil {
		return 0, err
	}
	if int(readBytes) < len(p) {
		// ReadAt is more strict than Read.
		return 0, errors.Errorf("Could only read %d bytes", readBytes)
	}

	return int(readBytes), nil
}
782552
func charAt(s string, i int) byte {
	if i >= 0 && i < len(s) {
		return s[i]
	}
	return s[0]
}
1061666
func MapStringStringSliceValueSet(m map[string][]string) []string {
	set := make(map[string]struct{})
	for _, slice := range m {
		for _, v := range slice {
			set[v] = struct{}{}
		}
	}

	flat := make([]string, 0, len(set))
	for k := range set {
		flat = append(flat, k)
	}
	return flat
}
179913
func (pool *stringPool) ReadAt(index TokenID) (string, error) {
	if index < TokenID(0) || index >= TokenID(len(pool.items)) {
		return "", errors.New("index out of range")
	}
	pool.RLock()
	item := pool.items[int(index)]
	pool.RUnlock()
	compressed := pool.buffer.Bytes()[item.begin:item.end]
	decompressed, error := smaz.Decompress(compressed)
	if error != nil {
		return "", error
	}
	return string(decompressed), nil
}
76810
func chunkStrings(s []*string, size int) [][]*string {
	var chunks [][]*string
	for len(s) > 0 {
		end := size
		if len(s) < size {
			end = len(s)
		}

		chunks = append(chunks, s[0:end])
		s = s[end:]
	}
	return chunks
}
987494
func (eng *Engine) SetAt(t time.Time, name string, value interface{}, tags ...Tag) {
	eng.measure(t, name, value, Gauge, tags...)
}
1113996
func (r *bufferingReaderAt) ReadAt(p []byte, offset int64) (read int, err error) {
	if len(p) == 0 {
		return r.r.ReadAt(p, offset)
	}

	r.l.Lock()
	defer r.l.Unlock()

	bs := int64(r.blockSize)
	blockOff := int64((offset / bs) * bs) // block-aligned offset

	// Sequentially read blocks that intersect with the requested segment.
	for {
		// err here may be EOF or some other error. We consume all data first and
		// deal with errors later.
		data, err := r.readBlock(blockOff)

		// The first block may be read from the middle, since 'min' may be less than
		// 'offset'.
		if offset > blockOff {
			pos := offset - blockOff // position inside the block to read from
			if pos < int64(len(data)) {
				data = data[pos:] // grab the tail of the block
			} else {
				data = nil // we probably hit EOF before the requested offset
			}
		}

		// 'copy' copies min of len(data) and whatever space is left in 'p', so this
		// is always safe. The last block may be copied partially (if there's no
		// space left in 'p').
		read += copy(p[read:], data)

		switch {
		case read == len(p):
			// We managed to read everything we wanted, ignore the last error, if any.
			return read, nil
		case err != nil:
			return read, err
		}

		// The last read was successful. Per ReaderAt contract (that we double
		// checked in readBlock) it means it read ALL requested data (and we request
		// 'bs' bytes). So move on to the next block.
		blockOff += bs
	}
}
192908
func (eng *Engine) AddAt(t time.Time, name string, value interface{}, tags ...Tag) {
	eng.measure(t, name, value, Counter, tags...)
}
560584
func (f *File) ReadAt(buf []byte, off int64) (n int, err error) {
	size := f.Size()
	if off >= size {
		return 0, io.EOF
	}
	if n = len(buf); int64(n) > size-off {
		n = int(size - off)
	}

	lfrag := int(uint32(off) % uint32(f.fs.BlockSize))
	off -= int64(lfrag)
	want := lfrag + n
	rfrag := -want & (f.fs.BlockSize - 1)
	want += rfrag

	offb := uint32(off / int64(f.fs.BlockSize))

	nblock := want / f.fs.BlockSize
	for i := 0; i < nblock; i++ {
		b, err := f.dblock(offb + uint32(i))
		if err != nil {
			return 0, err
		}
		dbuf, err := f.fs.readData(b, 0, nil)
		if err != nil {
			return 0, err
		}
		m := copy(buf, dbuf[lfrag:])
		buf = buf[m:]
		lfrag = 0
	}
	return n, nil
}
1291376
func (db *RedisDB) stringSet(k, v string) {
	db.del(k, false)
	db.keys[k] = "string"
	db.stringKeys[k] = v
	db.keyVersion[k]++
}
1086049
func (rb *reorderBuffer) bytesAt(n int) []byte {
	inf := rb.rune[n]
	return rb.byte[inf.pos : int(inf.pos)+int(inf.size)]
}
290187
func (f *File) ReadAt(buf []byte, offset int64) (int, error) {
	bytesRead, err := f.readAt(buf, offset)

	if f.LogLevel >= 2 {
		bytesWanted := int64(len(buf))
		start := offset
		end := offset + bytesWanted

		var readDesc string
		if bytesWanted == int64(bytesRead) {
			readDesc = "full"
		} else if bytesRead == 0 {
			readDesc = fmt.Sprintf("partial (%d of %d)", bytesRead, bytesWanted)
		} else {
			readDesc = "zero"
		}
		if err != nil {
			readDesc += fmt.Sprintf(", with err %v", err)
		}
		f.log2("[%9d-%9d] (ReadAt) %s", start, end, readDesc)
	}
	return bytesRead, err
}