// pos translates the row ID and column ID into a position in the storage bitmap.
185546
func (f *fragment) pos(rowID, columnID uint64) (uint64, error) {
	// Return an error if the column ID is out of the range of the fragment's shard.
	minColumnID := f.shard * ShardWidth
	if columnID < minColumnID || columnID >= minColumnID+ShardWidth {
		return 0, errors.Errorf("column:%d out of bounds", columnID)
	}
	return pos(rowID, columnID), nil
}
1302607
func (f *fragment) rowFromStorage(rowID uint64) *Row {
	// Only use a subset of the containers.
	// NOTE: The start & end ranges must be divisible by container width.
	data := f.storage.OffsetRange(f.shard*ShardWidth, rowID*ShardWidth, (rowID+1)*ShardWidth)

	// Reference bitmap subrange in storage. We Clone() data because otherwise
	// row will contain pointers to containers in storage. This causes
	// unexpected results when we cache the row and try to use it later.
	// Basically, since we return the Row and release the fragment lock, the
	// underlying fragment storage could be changed or snapshotted and thrown
	// out at any point.
	row := &Row{
		segments: []rowSegment{{
			data:     *data.Clone(),
			shard:    f.shard,
			writable: false, // this Row will probably be cached and shared, so it must be read only.
		}},
	}
	row.invalidateCount()

	return row
}
885563
func bitPos(s []byte, bit bool) int {
	for i, b := range s {
		for j, set := range toBits(b) {
			if set == bit {
				return i*8 + j
			}
		}
	}
	return -1
}
26803
func (e *Error) Position() (int, int, string) {
	if e.line == 0 {
		e.line, e.column, e.context = Position(e.r, e.Offset)
	}
	return e.line, e.column, e.context
}
878119
func (m *Monitor) GetPos() (x, y int) {
	var xpos, ypos C.int
	C.glfwGetMonitorPos(m.data, &xpos, &ypos)
	panicError()
	return int(xpos), int(ypos)
}
1280777
func (v *View) realPosition(vx, vy int) (x, y int, err error) {
	vx = v.ox + vx
	vy = v.oy + vy

	if vx < 0 || vy < 0 {
		return 0, 0, errors.New("invalid point")
	}

	if len(v.viewLines) == 0 {
		return vx, vy, nil
	}

	if vy < len(v.viewLines) {
		vline := v.viewLines[vy]
		x = vline.linesX + vx
		y = vline.linesY
	} else {
		vline := v.viewLines[len(v.viewLines)-1]
		x = vx
		y = vline.linesY + vy - len(v.viewLines) + 1
	}

	return x, y, nil
}
867056
func (r *importReader) pos() {
	if r.int64() != deltaNewFile {
	} else if l := r.int64(); l == -1 {
	} else {
		r.string()
	}
}
67353
func makePosition(filepart int, offset int) xlog.Position {
	return xlog.Position(fmt.Sprintf("%X/%08X", filepart, offset))
}
313122
func (pos *Position) Hash() [16]byte {
	sq := "-"
	if pos.enPassantSquare != NoSquare {
		sq = pos.enPassantSquare.String()
	}
	s := pos.turn.String() + ":" + pos.castleRights.String() + ":" + sq
	for _, p := range allPieces {
		bb := pos.board.bbForPiece(p)
		s += ":" + strconv.FormatUint(uint64(bb), 16)
	}
	return md5.Sum([]byte(s))
}
367943
func (f *File) loc(pos token.Pos) string {
	if pos == token.NoPos {
		return ""
	}
	// Do not print columns. Because the pos often points to the start of an
	// expression instead of the inner part with the actual error, the
	// precision can mislead.
	posn := f.fset.Position(pos)
	return fmt.Sprintf("%s:%d", posn.Filename, posn.Line)
}
394151
func posFromOffset(offset int, source []byte) (int, int, string) {
	if source == nil {
		return 0, 0, ""
	}
	return util.Highlight(source, int64(offset))
}
88317
func (p POSMap) Add(pos []string) POS {
	ret := make(POS, 0, len(pos))
	for _, name := range pos {
		id := p.add(name)
		ret = append(ret, id)
	}
	return ret
}
1039763
func (pos *Position) MarshalText() (text []byte, err error) {
	return []byte(pos.String()), nil
}
208507
func (db *DB) BitPos(key []byte, on int, start int, end int) (int64, error) {
	if err := checkKeySize(key); err != nil {
		return 0, err
	}

	if (on & ^1) != 0 {
		return 0, fmt.Errorf("bit must be 0 or 1, not %d", on)
	}

	var skipValue uint8
	if on == 0 {
		skipValue = 0xFF
	}

	key = db.encodeKVKey(key)
	value, err := db.bucket.Get(key)
	if err != nil {
		return 0, err
	}

	start, end = getRange(start, end, len(value))
	value = value[start : end+1]

	for i, v := range value {
		if uint8(v) != skipValue {
			for j := 0; j < 8; j++ {
				isNull := uint8(v)&(1<<uint8(7-j)) == 0

				if (on == 1 && !isNull) || (on == 0 && isNull) {
					return int64((start+i)*8 + j), nil
				}
			}
		}
	}

	return -1, nil
}
624270
func (m *subMenu) Insert(pos int, i *MenuItem) (err error) {
	if err = m.isActionable(); err != nil {
		return
	}
	if pos > len(m.items) {
		err = fmt.Errorf("Submenu has %d items, position %d is invalid", len(m.items), pos)
		return
	}
	if _, err = synchronousEvent(m.c, m, m.w, Event{Name: EventNameSubMenuCmdInsert, TargetID: m.id, MenuItem: i.toEvent(), MenuItemPosition: PtrInt(pos)}, EventNameSubMenuEventInserted); err != nil {
		return
	}
	m.items = append(m.items[:pos], append([]*MenuItem{i}, m.items[pos:]...)...)
	return
}
219576
func (self *FileSet) Position(idx Idx) *Position {
	position := &Position{}
	for _, file := range self.files {
		if idx <= Idx(file.base+len(file.src)) {
			offset := int(idx) - file.base
			src := file.src[:offset]
			position.Filename = file.name
			position.Offset = offset
			position.Line = 1 + strings.Count(src, "\n")
			if index := strings.LastIndex(src, "\n"); index >= 0 {
				position.Column = offset - index
			} else {
				position.Column = 1 + len(src)
			}
		}
	}
	return position
}
620052
func (s *Scanner) pos() ast.Position {
	return ast.Position{Line: s.line + 1, Column: s.offset - s.lineHead + 1}
}