// NewBitmapFromBlocks returns a new Bitmap from a slice of Blocks. This
// a convenient way to explicitly create Bitmaps in code, such as when writing
// tests.
516955
func NewBitmapFromBlocks(blocks []Block) *Bitmap {
	return &Bitmap{size: len(blocks) * bitsPerBlock, store: blocks}
}
56652
func BitmapOf(dat ...uint32) *Bitmap {
	ans := NewBitmap()
	ans.AddMany(dat)
	return ans
}
63529
func NewBitmap(bytes []byte) *Bitmap {
	var numBytes = len(bytes)
	var storeSize = sizeRequired(numBytes, bytesPerBlock)
	var s = make([]Block, 0, storeSize)

	var buf Block
	var hasPartialBuf bool
	var lastM = bytesPerBlock - 1
	for i, b := range bytes {
		var m = i % bytesPerBlock
		buf |= Block(b) << uint(bitsPerBlock-(m+1)*bitsPerByte)
		if lastM == m {
			s = append(s, buf)
			buf = 0
			hasPartialBuf = false
		} else {
			hasPartialBuf = true
		}
	}
	if hasPartialBuf {
		s = append(s, buf)
	}
	return &Bitmap{size: numBytes * bitsPerByte, store: s}
}
690409
func NewFileBlockWithPtrs(isInd bool) BlockWithPtrs {
	fb := NewFileBlock().(*FileBlock)
	fb.IsInd = isInd
	return fb
}
204366
func NewBlockFromJSON(data string) (*Block, error) {
	b := &Block{
		block: new(types.Block),
	}
	if err := json.Unmarshal([]byte(data), b.block); err != nil {
		return nil, err
	}
	return b, nil
}
1066293
func (c *Container) bitmapToArray() {
	statsHit("bitmapToArray")
	bitmap := c.bitmap()
	c.setBitmap(nil)
	c.typ = containerArray
	c.mapped = false

	// return early if empty
	if c.n == 0 {
		c.setArray(nil)
		return
	}
	n := int32(0)

	array := make([]uint16, c.n)
	for i, word := range bitmap {
		for word != 0 {
			t := word & -word
			if roaringParanoia {
				if n >= c.n {
					panic("bitmap has more bits set than container.n")
				}
			}
			array[n] = uint16((i*64 + int(popcount(t-1))))
			n++
			word ^= t
		}
	}
	if roaringParanoia {
		if n != c.n {
			panic("bitmap has fewer bits set than container.n")
		}
	}
	c.setArray(array)
}
730653
func ToBitmap(bit C.MMBitmapRef) Bitmap {
	bitmap := Bitmap{
		ImgBuf:        (*uint8)(bit.imageBuffer),
		Width:         int(bit.width),
		Height:        int(bit.height),
		Bytewidth:     int(bit.bytewidth),
		BitsPixel:     uint8(bit.bitsPerPixel),
		BytesPerPixel: uint8(bit.bytesPerPixel),
	}

	return bitmap
}
673460
func NewBitArray(bitmapLen uint32, valueBitWidth byte) *BitArray {
	return new(BitArray).Init(bitmapLen, valueBitWidth)
}
611372
func (e *executor) executeBitmapCall(ctx context.Context, index string, c *pql.Call, shards []uint64, opt *execOptions) (*Row, error) {
	span, ctx := tracing.StartSpanFromContext(ctx, "Executor.executeBitmapCall")
	defer span.Finish()

	// Execute calls in bulk on each remote node and merge.
	mapFn := func(shard uint64) (interface{}, error) {
		return e.executeBitmapCallShard(ctx, index, c, shard)
	}

	// Merge returned results at coordinating node.
	reduceFn := func(prev, v interface{}) interface{} {
		other, _ := prev.(*Row)
		if other == nil {
			other = NewRow()
		}
		other.Merge(v.(*Row))
		return other
	}

	other, err := e.mapReduce(ctx, index, shards, c, opt, mapFn, reduceFn)
	if err != nil {
		return nil, errors.Wrap(err, "map reduce")
	}

	// Attach attributes for non-BSI Row() calls.
	// If the column label is used then return column attributes.
	// If the row label is used then return bitmap attributes.
	row, _ := other.(*Row)
	if c.Name == "Row" && !c.HasConditionArg() {
		if opt.ExcludeRowAttrs {
			row.Attrs = map[string]interface{}{}
		} else {
			idx := e.Holder.Index(index)
			if idx != nil {
				if columnID, ok, err := c.UintArg("_" + columnLabel); ok && err == nil {
					attrs, err := idx.ColumnAttrStore().Attrs(columnID)
					if err != nil {
						return nil, errors.Wrap(err, "getting column attrs")
					}
					row.Attrs = attrs
				} else if err != nil {
					return nil, err
				} else {
					// field, _ := c.Args["field"].(string)
					fieldName, _ := c.FieldArg()
					if fr := idx.Field(fieldName); fr != nil {
						rowID, _, err := c.UintArg(fieldName)
						if err != nil {
							return nil, errors.Wrap(err, "getting row")
						}
						attrs, err := fr.RowAttrStore().Attrs(rowID)
						if err != nil {
							return nil, errors.Wrap(err, "getting row attrs")
						}
						row.Attrs = attrs
					}
				}
			}
		}
	}

	if opt.ExcludeColumns {
		row.segments = []rowSegment{}
	}

	return row, nil
}
70992
func (bps *blockPutStateDisk) AddNewBlock(
	ctx context.Context, blockPtr data.BlockPointer, block data.Block,
	readyBlockData data.ReadyBlockData, syncedCb func() error) error {
	// Add the pointer and the cb to the memory-based put state, and
	// put the ready data directly into the disk cache.
	err := bps.diskCache.Put(
		ctx, bps.kmd.TlfID(), blockPtr.ID, readyBlockData.Buf,
		readyBlockData.ServerHalf)
	if err != nil {
		return err
	}

	if _, isDir := block.(*data.DirBlock); isDir {
		bps.isDir[blockPtr] = true
	}

	return bps.blockPutStateMemory.AddNewBlock(
		ctx, blockPtr, nil, data.ReadyBlockData{}, syncedCb)
}
609857
func FindCBitmap(bmp CBitmap, args ...interface{}) (int, int) {
	return FindBitmap(ToMMBitmapRef(bmp), args...)
}
1260081
func NewImageFromPixbuf(pixbuf *gdkpixbuf.Pixbuf) *Image {
	return &Image{Misc{Widget{C.gtk_image_new_from_pixbuf((*C.GdkPixbuf)(unsafe.Pointer(pixbuf.GPixbuf)))}}}
}
691579
func (plugin *cinderPlugin) NewBlockVolumeMapper(spec *volume.Spec, pod *v1.Pod, _ volume.VolumeOptions) (volume.BlockVolumeMapper, error) {
	// If this is called via GenerateUnmapDeviceFunc(), pod is nil.
	// Pass empty string as dummy uid since uid isn't used in the case.
	var uid types.UID
	if pod != nil {
		uid = pod.UID
	}

	return plugin.newBlockVolumeMapperInternal(spec, uid, &DiskUtil{}, plugin.host.GetMounter(plugin.GetPluginName()))
}
48481
func NewBitFlags(permissibleOptions []string, defaultOptions string, flagMap map[string]int) (*BitFlags, error) {
	ol, err := NewOptionList(permissibleOptions, defaultOptions)
	if err != nil {
		return nil, err
	}

	bf := &BitFlags{
		OptionList: ol,
		FlagMap:    flagMap,
	}
	bf.typeName = "BitFlags"

	if err := bf.Set(defaultOptions); err != nil {
		return nil, errwrap.Wrap(errors.New("problem setting defaults"), err)
	}

	return bf, nil
}
862068
func NewOptionGroupBlockElement(label *TextBlockObject, options ...*OptionBlockObject) *OptionGroupBlockObject {
	return &OptionGroupBlockObject{
		Label:   label,
		Options: options,
	}
}
929819
func ActionBitmap(actions ...ofp.ActionType) (bits uint32) {
	for _, action := range actions {
		bits = shl(bits, uint32(action))
	}

	return
}
196812
func NewMerkleBlock(block *btcutil.Block, filter *Filter) (*wire.MsgMerkleBlock, []uint32) {
	numTx := uint32(len(block.Transactions()))
	mBlock := merkleBlock{
		numTx:       numTx,
		allHashes:   make([]*chainhash.Hash, 0, numTx),
		matchedBits: make([]byte, 0, numTx),
	}

	// Find and keep track of any transactions that match the filter.
	var matchedIndices []uint32
	for txIndex, tx := range block.Transactions() {
		if filter.MatchTxAndUpdate(tx) {
			mBlock.matchedBits = append(mBlock.matchedBits, 0x01)
			matchedIndices = append(matchedIndices, uint32(txIndex))
		} else {
			mBlock.matchedBits = append(mBlock.matchedBits, 0x00)
		}
		mBlock.allHashes = append(mBlock.allHashes, tx.Hash())
	}

	// Calculate the number of merkle branches (height) in the tree.
	height := uint32(0)
	for mBlock.calcTreeWidth(height) > 1 {
		height++
	}

	// Build the depth-first partial merkle tree.
	mBlock.traverseAndBuild(height, 0)

	// Create and return the merkle block.
	msgMerkleBlock := wire.MsgMerkleBlock{
		Header:       block.MsgBlock().Header,
		Transactions: mBlock.numTx,
		Hashes:       make([]*chainhash.Hash, 0, len(mBlock.finalHashes)),
		Flags:        make([]byte, (len(mBlock.bits)+7)/8),
	}
	for _, hash := range mBlock.finalHashes {
		msgMerkleBlock.AddTxHash(hash)
	}
	for i := uint32(0); i < uint32(len(mBlock.bits)); i++ {
		msgMerkleBlock.Flags[i/8] |= mBlock.bits[i] << (i % 8)
	}
	return &msgMerkleBlock, matchedIndices
}