// InsertPlan means inserting plan between two plans.
4247
func InsertPlan(parent Plan, child Plan, insert Plan) error {
	err := child.ReplaceParent(parent, insert)
	if err != nil {
		return errors.Trace(err)
	}
	err = parent.ReplaceChild(child, insert)
	if err != nil {
		return errors.Trace(err)
	}
	insert.AddChild(child)
	insert.AddParent(parent)
	return nil
}
1288234
func (p *ProxyLB) SetPlan(plan ProxyLBPlan) {
	p.ServiceClass = fmt.Sprintf("cloud/proxylb/plain/%d", plan)
}
1059289
func InsertPredicateKeyToAlgorithmProviderMap(key string) {
	schedulerFactoryMutex.Lock()
	defer schedulerFactoryMutex.Unlock()

	for _, provider := range algorithmProviderMap {
		provider.FitPredicateKeys.Insert(key)
	}
	return
}
481223
func (c *Client) GetPlans() ([]Plan, error) {
	var planMap map[string]Plan
	if err := c.get(`plans/list`, &planMap); err != nil {
		return nil, err
	}

	var p plans
	for _, plan := range planMap {
		p = append(p, plan)
	}

	sort.Sort(plans(p))
	return p, nil
}
1012390
func getPlanFromPath(path string) (*plans.Plan, error) {
	pr, err := planfile.Open(path)
	if err != nil {
		return nil, err
	}
	plan, err := pr.ReadPlan()
	if err != nil {
		return nil, err
	}
	return plan, nil
}
6204
func (p *Planner) Plan() (*ir.Policy, error) {

	for _, q := range p.queries {
		p.curr = &ir.Block{}
		defined := false

		if err := p.planQuery(q, 0, func() error {
			p.appendStmt(ir.ReturnStmt{
				Code: ir.Defined,
			})
			defined = true
			return nil
		}); err != nil {
			return nil, err
		}

		if defined {
			p.blocks = append(p.blocks, *p.curr)
		}
	}

	p.blocks = append(p.blocks, ir.Block{
		Stmts: []ir.Stmt{
			ir.ReturnStmt{
				Code: ir.Undefined,
			},
		},
	})

	policy := ir.Policy{
		Static: ir.Static{
			Strings: p.strings,
		},
		Plan: ir.Plan{
			Blocks: p.blocks,
		},
	}

	return &policy, nil
}
136123
func readPlan(r io.Reader) (plan *planModel, err error) {
	data, err := ioutil.ReadAll(r)
	if err != nil {
		return
	}

	var doc planModel
	err = yaml.Unmarshal(data, &doc)
	if err != nil {
		return
	}
	return &doc, nil
}
840906
func (api *ProductServerAPI) IsValidPlan(core int, memGB int, gen sacloud.PlanGenerations) (bool, error) {

	productServer, err := api.GetBySpec(core, memGB, gen)

	if err != nil {
		return false, err
	}

	if productServer == nil {
		return false, fmt.Errorf("Server Plan[core:%d, memory:%d, gen:%d] is not found", core, memGB, gen)
	}

	if productServer.Availability != sacloud.EAAvailable {
		return false, fmt.Errorf("Server Plan[core:%d, memory:%d, gen:%d] is not available", core, memGB, gen)
	}

	return true, nil
}
406792
func (rp *ReplicatorPlan) buildExecutionPlan(fieldEvent *binlogdatapb.FieldEvent) (*TablePlan, error) {
	prelim := rp.TablePlans[fieldEvent.TableName]
	if prelim == nil {
		// Unreachable code.
		return nil, fmt.Errorf("plan not found for %s", fieldEvent.TableName)
	}
	if prelim.Insert != nil {
		tplanv := *prelim
		tplanv.Fields = fieldEvent.Fields
		return &tplanv, nil
	}
	// select * construct was used. We need to use the field names.
	tplan, err := rp.buildFromFields(prelim.TargetName, fieldEvent.Fields)
	if err != nil {
		return nil, err
	}
	tplan.Fields = fieldEvent.Fields
	return tplan, nil
}
1254778
func (p *insertPlan) String(ctx context.Context) string {
	b := bytes.NewBufferString("INSERT plan:\n\n")
	for _, g := range p.stm.OutputGraphs() {
		b.WriteString(fmt.Sprintf("store(%q).Graph(%q).AddTriples(_, data)\n", p.store.Name(nil), g))
	}
	b.WriteString("where data:\n")
	for _, t := range p.stm.Data() {
		b.WriteString("\t")
		b.WriteString(t.String())
		b.WriteString("\n")
	}
	return b.String()
}
71572
func (s *MarketplaceService) ListPlans(ctx context.Context, opt *ListOptions) ([]*MarketplacePlan, *Response, error) {
	uri := s.marketplaceURI("plans")
	u, err := addOptions(uri, opt)
	if err != nil {
		return nil, nil, err
	}

	req, err := s.client.NewRequest("GET", u, nil)
	if err != nil {
		return nil, nil, err
	}

	var plans []*MarketplacePlan
	resp, err := s.client.Do(ctx, req, &plans)
	if err != nil {
		return nil, resp, err
	}

	return plans, resp, nil
}
983836
func AveragePlan(nodesInfo []types.NodeInfo, need, limit int) ([]types.NodeInfo, error) {
	nodesInfoLength := len(nodesInfo)
	sort.Slice(nodesInfo, func(i, j int) bool { return nodesInfo[i].Capacity < nodesInfo[j].Capacity })
	p := sort.Search(nodesInfoLength, func(i int) bool { return nodesInfo[i].Capacity >= need })
	if p == nodesInfoLength {
		return nil, types.ErrInsufficientCap
	}
	nodesInfo = nodesInfo[p:]
	if limit > 0 {
		nodesInfo = nodesInfo[:limit]
	}
	for i := range nodesInfo {
		nodesInfo[i].Deploy = need
		nodesInfo[i].Capacity -= need
	}

	log.Debugf("[AveragePlan] nodesInfo: %v", nodesInfo)
	return nodesInfo, nil
}
1032528
func (p *basePlan) AddChild(child Plan) {
	p.children = append(p.children, child)
}
666622
func WithCompactionPlanner(planner tsm1.CompactionPlanner) Option {
	return func(e *Engine) {
		e.engine.WithCompactionPlanner(planner)
	}
}
1148544
func (t *Table) InsertColumn(column int) *Table {
	for row := range t.cells {
		if column >= len(t.cells[row]) {
			continue
		}
		t.cells[row] = append(t.cells[row], nil)             // Extend by one.
		copy(t.cells[row][column+1:], t.cells[row][column:]) // Shift to the right.
		t.cells[row][column] = &TableCell{}                  // New element is an uninitialized table cell.
	}
	return t
}
885825
func InsertPendingOp(timestamp time.Time, targetID string, op SampleOp, size int) OpID {
	mutexPendingOps.Lock()
	defer mutexPendingOps.Unlock()

	var id int
	if len(pendingOpsFreeSlot) > 0 {
		//reuse recently freed id
		id = pendingOpsFreeSlot[len(pendingOpsFreeSlot)-1]
		pendingOpsFreeSlot = pendingOpsFreeSlot[:len(pendingOpsFreeSlot)-1]
	} else {
		id = pendingOpEmptySlot()
	}
	pendingOps[id] = dataPoint{targetIndex(targetID), op, timestamp, 0, size, false}
	log.Debug("InsertPendingOp id=", id)
	return OpID(id)
}
675399
func (self *PlanClient) ListN(count int, offset int) ([]*Plan, error) {
	// define a wrapper function for the Plan List, so that we can
	// cleanly parse the JSON
	type listPlanResp struct{ Data []*Plan }
	resp := listPlanResp{}

	// add the count and offset to the list of url values
	values := url.Values{
		"count":  {strconv.Itoa(count)},
		"offset": {strconv.Itoa(offset)},
	}

	err := query("GET", "/v1/plans", values, &resp)
	if err != nil {
		return nil, err
	}
	return resp.Data, nil
}