// ConstructPBComparator is TODO
353353
func (c *BinaryComparator) ConstructPBComparator() (*pb.Comparator, error) {
	serializedComparator, err := proto.Marshal((*pb.BinaryComparator)(c))
	if err != nil {
		return nil, err
	}
	comparator := &pb.Comparator{
		Name:                 proto.String(comparatorPath + "BinaryComparator"),
		SerializedComparator: serializedComparator,
	}
	return comparator, nil
}
84223
func MultithreadedSortComparators(comparators Comparators) Comparators {
	toBeSorted := make(Comparators, len(comparators))
	copy(toBeSorted, comparators)

	var wg sync.WaitGroup

	numCPU := int64(runtime.NumCPU())
	if numCPU%2 == 1 { // single core machine
		numCPU++
	}

	chunks := chunk(toBeSorted, numCPU)
	wg.Add(len(chunks))
	for i := 0; i < len(chunks); i++ {
		go func(i int) {
			sortBucket(chunks[i])
			wg.Done()
		}(i)
	}

	wg.Wait()
	todo := make([]Comparators, len(chunks)/2)
	for {
		todo = todo[:len(chunks)/2]
		wg.Add(len(chunks) / 2)
		for i := 0; i < len(chunks); i += 2 {
			go func(i int) {
				todo[i/2] = SymMerge(chunks[i], chunks[i+1])
				wg.Done()
			}(i)
		}

		wg.Wait()

		chunks = copyChunk(todo)
		if len(chunks) == 1 {
			break
		}
	}

	return chunks[0]
}
375343
func ConstructBTLPolicy(collInfoProvider collectionInfoProvider) BTLPolicy {
	return &LSCCBasedBTLPolicy{
		collInfoProvider: collInfoProvider,
		cache:            make(map[btlkey]uint64),
	}
}
315991
func CommaBuilder(env *Zlisp, name string, args []Sexp) (Sexp, error) {

	n := len(args)
	if n < 1 {
		return SexpNull, nil
	}

	res := make([]Sexp, 0)
	for i := range args {
		commaHelper(args[i], &res)
	}
	return &SexpArray{Val: res}, nil
}
1247701
func (pb *ProgressBar) Postfix(postfix string) *ProgressBar {
	pb.mu.Lock()
	defer pb.mu.Unlock()
	pb.postfix = postfix
	return pb
}
294912
func MuxerConstructor(m interface{}) (MuxC, error) {
	// Already constructed?
	if t, ok := m.(mux.Transport); ok {
		return func(_ host.Host) (mux.Transport, error) {
			return t, nil
		}, nil
	}

	ctor, err := makeConstructor(m, muxType, muxArgTypes)
	if err != nil {
		return nil, err
	}
	return func(h host.Host) (mux.Transport, error) {
		t, err := ctor(h, nil)
		if err != nil {
			return nil, err
		}
		return t.(mux.Transport), nil
	}, nil
}
212471
func toAddrPointer(i *interface{}, isptr, deref bool) pointer {
	v := reflect.ValueOf(*i)
	u := reflect.New(v.Type())
	u.Elem().Set(v)
	if deref {
		u = u.Elem()
	}
	return pointer{v: u}
}
255425
func PgProcParams(db XODB, schema string, proc string) ([]*ProcParam, error) {
	var err error

	// sql query
	const sqlstr = `SELECT ` +
		`UNNEST(STRING_TO_ARRAY(oidvectortypes(p.proargtypes), ', ')) ` + // ::varchar AS param_type
		`FROM pg_proc p ` +
		`JOIN ONLY pg_namespace n ON p.pronamespace = n.oid ` +
		`WHERE n.nspname = $1 AND p.proname = $2`

	// run query
	XOLog(sqlstr, schema, proc)
	q, err := db.Query(sqlstr, schema, proc)
	if err != nil {
		return nil, err
	}
	defer q.Close()

	// load results
	res := []*ProcParam{}
	for q.Next() {
		pp := ProcParam{}

		// scan
		err = q.Scan(&pp.ParamType)
		if err != nil {
			return nil, err
		}

		res = append(res, &pp)
	}

	return res, nil
}
625092
func (h *TermsHashPerFieldImpl) _constructor(spi TermsHashPerFieldSPI,
	streamCount int, fieldState *FieldInvertState,
	termsHash TermsHash, nextPerField TermsHashPerField,
	fieldInfo *FieldInfo) {

	termsHashImpl := termsHash.fields()

	h.spi = spi
	h.intPool = termsHashImpl.intPool
	h.bytePool = termsHashImpl.bytePool
	h.termBytePool = termsHashImpl.termBytePool
	h.docState = termsHashImpl.docState
	h.termsHash = termsHash
	h.bytesUsed = termsHashImpl.bytesUsed
	h.fieldState = fieldState
	h.streamCount = streamCount
	h.numPostingInt = 2 * streamCount
	h.fieldInfo = fieldInfo
	h.nextPerField = nextPerField
	byteStarts := newPostingsBytesStartArray(h, h.bytesUsed)
	h.bytesHash = util.NewBytesRefHash(termsHashImpl.termBytePool, HASH_INIT_SIZE, byteStarts)
}
1097234
func pcfObject(jsonMap map[string]interface{}) (string, error) {
	pairs := make(stringPairs, 0, len(jsonMap))

	// Remember the namespace to fully qualify names later
	var namespace string
	if namespaceJSON, ok := jsonMap["namespace"]; ok {
		if namespaceStr, ok := namespaceJSON.(string); ok {
			// and it's value is string (otherwise invalid schema)
			namespace = namespaceStr
		}
	}

	for k, v := range jsonMap {

		// Reduce primitive schemas to their simple form.
		if len(jsonMap) == 1 && k == "type" {
			if t, ok := v.(string); ok {
				return "\"" + t + "\"", nil
			}
		}

		// Only keep relevant attributes (strip 'doc', 'alias', 'namespace')
		if _, ok := fieldOrder[k]; !ok {
			continue
		}

		// Add namespace to a non-qualified name.
		if k == "name" && namespace != "" {
			// Check if the name isn't already qualified.
			if t, ok := v.(string); ok && !strings.ContainsRune(t, '.') {
				v = namespace + "." + t
			}
		}

		// Only fixed type allows size, and we must convert a string size to a
		// float.
		if k == "size" {
			if s, ok := v.(string); ok {
				s, err := strconv.ParseUint(s, 10, 0)
				if err != nil {
					// should never get here because already validated schema
					return "", fmt.Errorf("Fixed size ought to be number greater than zero: %v", s)
				}
				v = float64(s)
			}
		}

		pk, err := parsingCanonicalForm(k)
		if err != nil {
			return "", err
		}
		pv, err := parsingCanonicalForm(v)
		if err != nil {
			return "", err
		}

		pairs = append(pairs, stringPair{k, pk + ":" + pv})
	}

	// Sort keys by their order in specification.
	sort.Sort(byAvroFieldOrder(pairs))
	return "{" + strings.Join(pairs.Bs(), ",") + "}", nil
}
34939
func (p pointer) appendPointer(q pointer) {
	s := (*[]unsafe.Pointer)(p.p)
	*s = append(*s, q.p)
}
534455
func NewPUBCOMP(opts *PUBCOMPOptions) (Packet, error) {
	// Initialize the options.
	if opts == nil {
		opts = &PUBCOMPOptions{}
	}

	// Validate the options.
	if err := opts.validate(); err != nil {
		return nil, err
	}

	// Create a PUBCOMP Packet.
	p := &PUBCOMP{
		PacketID: opts.PacketID,
	}

	// Set the variable header to the Packet.
	p.setVariableHeader()

	// Set the Fixed header to the Packet.
	p.setFixedHeader()

	// Return the Packet.
	return p, nil
}
1205655
func NewPCMByteBuffer(data []byte, format *Format) *PCMBuffer {
	return &PCMBuffer{
		Format:   format,
		DataType: Byte,
		Bytes:    data,
	}
}
892779
func (pdb *prefixDB) Iterator(start, end []byte) Iterator {
	pdb.mtx.Lock()
	defer pdb.mtx.Unlock()

	var pstart, pend []byte
	pstart = append(cp(pdb.prefix), start...)
	if end == nil {
		pend = cpIncr(pdb.prefix)
	} else {
		pend = append(cp(pdb.prefix), end...)
	}
	return newPrefixIterator(
		pdb.prefix,
		start,
		end,
		pdb.db.Iterator(
			pstart,
			pend,
		),
	)
}
765143
func constructCouchDBUrl(connectURL *url.URL, dbName string, pathElements ...string) *url.URL {
	var buffer bytes.Buffer
	buffer.WriteString(connectURL.String())
	if dbName != "" {
		buffer.WriteString("/")
		buffer.WriteString(encodePathElement(dbName))
	}
	for _, pathElement := range pathElements {
		buffer.WriteString("/")
		buffer.WriteString(encodePathElement(pathElement))
	}
	return &url.URL{Opaque: buffer.String()}
}
816708
func constructBlock(d *Dispenser) [][]interface{} {
	block := [][]interface{}{}

	for d.Next() {
		if d.Val() == "}" {
			break
		}
		block = append(block, constructLine(d))
	}

	return block
}
1283504
func (pb *primitiveBuilder) processTableExpr(tableExpr sqlparser.TableExpr) error {
	switch tableExpr := tableExpr.(type) {
	case *sqlparser.AliasedTableExpr:
		return pb.processAliasedTable(tableExpr)
	case *sqlparser.ParenTableExpr:
		err := pb.processTableExprs(tableExpr.Exprs)
		// If it's a route, preserve the parenthesis so things
		// don't associate differently when more things are pushed
		// into it. FROM a, (b, c) should not become FROM a, b, c.
		if rb, ok := pb.bldr.(*route); ok {
			sel := rb.Select.(*sqlparser.Select)
			sel.From = sqlparser.TableExprs{&sqlparser.ParenTableExpr{Exprs: sel.From}}
		}
		return err
	case *sqlparser.JoinTableExpr:
		return pb.processJoin(tableExpr)
	}
	panic(fmt.Sprintf("BUG: unexpected table expression type: %T", tableExpr))
}