// NewPartition returns a Partition instance which is loaded with data from r (assumed
// to be of the output format from the word2vec command with -classes arg).
185691
func NewPartition(r io.Reader) (*Partition, error) {
	scanner := bufio.NewScanner(r)
	words := make(map[string]int)
	classes := make(map[int][]string)

	i := 0
	for scanner.Scan() {
		line := scanner.Text()

		fields := strings.Fields(line)
		if len(fields) != 2 {
			return nil, fmt.Errorf("[line: %d] expected 2 fields, instead got: %v", i+1, len(fields))
		}

		w := fields[0]
		c, err := strconv.Atoi(fields[1])
		if err != nil {
			return nil, fmt.Errorf("[line: %d] error parsing integer %#v: %v", i+1, fields[1], err)
		}

		words[w] = c
		classes[c] = append(classes[c], w)
		i++
	}

	err := scanner.Err()
	if err != nil {
		return nil, fmt.Errorf("[line: %d] scanner error: %v", i+1, err)
	}

	return &Partition{
		words:   words,
		classes: classes,
	}, nil
}
315368
func NewPartitionedBloomFilter(n uint, fpRate float64) *PartitionedBloomFilter {
	var (
		m          = OptimalM(n, fpRate)
		k          = OptimalK(fpRate)
		partitions = make([]*Buckets, k)
		s          = uint(math.Ceil(float64(m) / float64(k)))
	)

	for i := uint(0); i < k; i++ {
		partitions[i] = NewBuckets(s, 1)
	}

	return &PartitionedBloomFilter{
		partitions: partitions,
		hash:       fnv.New64(),
		m:          m,
		k:          k,
		s:          s,
	}
}
997907
func newPartFromBytes(raw []byte, contentType string, contentDisposition string, contentID string) *Message {
	headers := Header{}

	if len(contentType) > 0 {
		headers.Set("Content-Type", contentType)
	} else {
		headers.Set("Content-Type", "application/octet-stream")
	}

	if len(contentDisposition) > 0 {
		headers.Set("Content-Disposition", contentDisposition)
	}

	if len(contentID) > 0 {
		headers.Set("Content-ID", "<"+contentID+">")
	}

	return &Message{Header: headers, Body: raw}
}
1061559
func parsePartitionKey(pkStr string) []string {
	pkStr = strings.TrimSpace(pkStr)
	var pks []string
	partitionKeys := strings.Split(pkStr, ",")
	for _, pk := range partitionKeys {
		npk := strings.TrimSpace(pk)
		if len(pk) > 0 {
			pks = append(pks, npk)
		}
	}
	return pks
}
134969
func (b *Blob) PartsSize() int64 {
	n := int64(0)
	for _, part := range b.ss.Parts {
		n += int64(part.Size)
	}
	return n
}
403895
func (d *ddl) CoalescePartitions(ctx sessionctx.Context, ident ast.Ident, spec *ast.AlterTableSpec) error {
	is := d.infoHandle.Get()
	schema, ok := is.SchemaByName(ident.Schema)
	if !ok {
		return errors.Trace(infoschema.ErrDatabaseNotExists.GenWithStackByArgs(schema))
	}
	t, err := is.TableByName(ident.Schema, ident.Name)
	if err != nil {
		return errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs(ident.Schema, ident.Name))
	}

	meta := t.Meta()
	if meta.GetPartitionInfo() == nil {
		return errors.Trace(ErrPartitionMgmtOnNonpartitioned)
	}

	// Coalesce partition can only be used on hash/key partitions.
	if meta.Partition.Type == model.PartitionTypeRange {
		return errors.Trace(ErrCoalesceOnlyOnHashPartition)
	}

	// We don't support coalesce partitions hash type partition now.
	if meta.Partition.Type == model.PartitionTypeHash {
		return errors.Trace(ErrUnsupportedCoalescePartition)
	}

	return errors.Trace(err)
}
680267
func (d *ddl) AddTablePartitions(ctx sessionctx.Context, ident ast.Ident, spec *ast.AlterTableSpec) error {
	is := d.infoHandle.Get()
	schema, ok := is.SchemaByName(ident.Schema)
	if !ok {
		return errors.Trace(infoschema.ErrDatabaseNotExists.GenWithStackByArgs(schema))
	}
	t, err := is.TableByName(ident.Schema, ident.Name)
	if err != nil {
		return errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs(ident.Schema, ident.Name))
	}

	meta := t.Meta()
	if meta.GetPartitionInfo() == nil {
		return errors.Trace(ErrPartitionMgmtOnNonpartitioned)
	}
	// We don't support add hash type partition now.
	if meta.Partition.Type == model.PartitionTypeHash {
		return errors.Trace(ErrUnsupportedAddPartition)
	}

	partInfo, err := buildPartitionInfo(meta, d, spec)
	if err != nil {
		return errors.Trace(err)
	}

	err = checkAddPartitionTooManyPartitions(uint64(len(meta.Partition.Definitions) + len(partInfo.Definitions)))
	if err != nil {
		return errors.Trace(err)
	}

	err = checkPartitionNameUnique(meta, partInfo)
	if err != nil {
		return errors.Trace(err)
	}

	err = checkAddPartitionValue(meta, partInfo)
	if err != nil {
		return errors.Trace(err)
	}

	job := &model.Job{
		SchemaID:   schema.ID,
		TableID:    meta.ID,
		Type:       model.ActionAddTablePartition,
		BinlogInfo: &model.HistoryInfo{},
		Args:       []interface{}{partInfo},
	}

	err = d.doDDLJob(ctx, job)
	err = d.callHookOnChanged(err)
	return errors.Trace(err)
}
37301
func NewCustomPartitioner(options ...HashPartitionerOption) PartitionerConstructor {
	return func(topic string) Partitioner {
		p := new(hashPartitioner)
		p.random = NewRandomPartitioner(topic)
		p.hasher = fnv.New32a()
		p.referenceAbs = false
		for _, option := range options {
			option(p)
		}
		return p
	}
}
267153
func partition(s Sortable, from, to int) int {
	i := from
	for j := from; j < to-1; j++ {
		if s.Less(j, to-1) {
			s.Swap(i, j)
			i++
		}
	}
	s.Swap(to-1, i)
	return i
}
931394
func NewPartInline(r io.Reader, filename string, contentID string) (*Message, error) {
	b, err := ioutil.ReadAll(r)
	if err != nil {
		return nil, err
	}
	return NewPartInlineFromBytes(b, filename, contentID), nil
}
952689
func newStaticPartitioner(partition int32) sarama.PartitionerConstructor {
	return func(topic string) sarama.Partitioner {
		return &staticPartitioner{partition}
	}
}
634728
func NewMurmur2HashPartitioner(topic string) kafka.Partitioner {
	p := new(Murmur2HashPartitioner)
	p.random = kafka.NewRandomPartitioner(topic)
	return p
}
556439
func NewPartial(org, project string, envs, services, identities, instances []string) (*PathExp, error) {
	return newPathexp(org, project, envs, services, identities, instances, false)
}
243823
func partition(data sort.Interface, lo, hi int) (int, int) {
	med := median(data, lo, hi)
	idx := lo
	data.Swap(med, hi)
	for i := lo; i < hi; i++ {
		if data.Less(i, hi) {
			data.Swap(i, idx)
			idx++
		}
	}
	data.Swap(idx, hi)
	return idx - 1, idx + 1
}
1108426
func (r *ring) getPartition(key []byte) *partition {
	return r.partitions[int(xxhash.Sum64(key)%partitions)]
}
1241460
func (c *MemberlistManager) GetPartitions() []int32 {
	c.RLock()
	defer c.RUnlock()
	return c.members[c.nodeName].Partitions
}
217907
func findPartitions(topic string, partitions []Partition) []int32 {
	var ids []int32
	for _, partition := range partitions {
		if partition.Topic == topic {
			ids = append(ids, int32(partition.ID))
		}
	}
	return ids
}