// NewMacroNode returns a MacroNode.
173682
func NewMacroNode(name string, args []string, body *BodyNode, p Pos) *MacroNode {
	return &MacroNode{p, TrimmableNode{}, name, args, body, ""}
}
278638
func newWorkerNode() (*VSphere, error) {
	var err error
	vs := VSphere{}
	vs.hostName, err = os.Hostname()
	if err != nil {
		klog.Errorf("Failed to get hostname. err: %+v", err)
		return nil, err
	}
	vs.vmUUID, err = GetVMUUID()
	if err != nil {
		klog.Errorf("Failed to get uuid. err: %+v", err)
		return nil, err
	}
	return &vs, nil
}
522521
func NewNode(opts NodeOptions) *Node {
	cfg := opts.Config
	if cfg == nil {
		cfg = DefaultNodeConfig()
	}
	if opts.TickInterval == 0 {
		opts.TickInterval = time.Second
	}
	if opts.SendTimeout == 0 {
		opts.SendTimeout = 2 * time.Second
	}

	raftStore := raft.NewMemoryStorage()

	n := &Node{
		cluster:   membership.NewCluster(),
		raftStore: raftStore,
		opts:      opts,
		Config: &raft.Config{
			ElectionTick:    cfg.ElectionTick,
			HeartbeatTick:   cfg.HeartbeatTick,
			Storage:         raftStore,
			MaxSizePerMsg:   cfg.MaxSizePerMsg,
			MaxInflightMsgs: cfg.MaxInflightMsgs,
			Logger:          cfg.Logger,
			CheckQuorum:     cfg.CheckQuorum,
		},
		doneCh:              make(chan struct{}),
		RemovedFromRaft:     make(chan struct{}),
		stopped:             make(chan struct{}),
		leadershipBroadcast: watch.NewQueue(),
		keyRotator:          opts.KeyRotator,
	}
	n.memoryStore = store.NewMemoryStore(n)

	if opts.ClockSource == nil {
		n.ticker = clock.NewClock().NewTicker(opts.TickInterval)
	} else {
		n.ticker = opts.ClockSource.NewTicker(opts.TickInterval)
	}

	n.reqIDGen = idutil.NewGenerator(uint16(n.Config.ID), time.Now())
	n.wait = newWait()

	n.cancelFunc = func(n *Node) func() {
		var cancelOnce sync.Once
		return func() {
			cancelOnce.Do(func() {
				close(n.stopped)
			})
		}
	}(n)

	return n
}
1299327
func newNode(index int, parent *node, hasher hash.Hash) *node {
	return &node{
		parent: parent,
		isLeft: index%2 == 0,
		hasher: hasher,
	}
}
1144444
func DefaultNewNode(config *cfg.Config, logger log.Logger) (*Node, error) {
	// Generate node PrivKey
	nodeKey, err := p2p.LoadOrGenNodeKey(config.NodeKeyFile())
	if err != nil {
		return nil, err
	}

	// Convert old PrivValidator if it exists.
	oldPrivVal := config.OldPrivValidatorFile()
	newPrivValKey := config.PrivValidatorKeyFile()
	newPrivValState := config.PrivValidatorStateFile()
	if _, err := os.Stat(oldPrivVal); !os.IsNotExist(err) {
		oldPV, err := privval.LoadOldFilePV(oldPrivVal)
		if err != nil {
			return nil, fmt.Errorf("Error reading OldPrivValidator from %v: %v\n", oldPrivVal, err)
		}
		logger.Info("Upgrading PrivValidator file",
			"old", oldPrivVal,
			"newKey", newPrivValKey,
			"newState", newPrivValState,
		)
		oldPV.Upgrade(newPrivValKey, newPrivValState)
	}

	return NewNode(config,
		privval.LoadOrGenFilePV(newPrivValKey, newPrivValState),
		nodeKey,
		proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
		DefaultGenesisDocProviderFunc(config),
		DefaultDBProvider,
		DefaultMetricsProvider(config.Instrumentation),
		logger,
	)
}
1303732
func NewFilterNode(filters []string, body Node, p Pos) *FilterNode {
	return &FilterNode{p, TrimmableNode{}, filters, body}
}
1326471
func NewMacd(fastTimePeriod int, slowTimePeriod int, signalTimePeriod int, selectData gotrade.DOHLCVDataSelectionFunc) (indicator *Macd, err error) {

	// the minimum fastTimePeriod for this indicator is 2
	if fastTimePeriod < 2 {
		return nil, errors.New("fastTimePeriod is less than the minimum (2)")
	}

	// check the maximum fastTimePeriod
	if fastTimePeriod > MaximumLookbackPeriod {
		return nil, errors.New("fastTimePeriod is greater than the maximum (100000)")
	}

	// the minimum slowTimePeriod for this indicator is 2
	if slowTimePeriod < 2 {
		return nil, errors.New("slowTimePeriod is less than the minimum (2)")
	}

	// check the maximum slowTimePeriod
	if slowTimePeriod > MaximumLookbackPeriod {
		return nil, errors.New("slowTimePeriod is greater than the maximum (100000)")
	}

	// the minimum signalTimePeriod for this indicator is 2
	if signalTimePeriod < 1 {
		return nil, errors.New("signalTimePeriod is less than the minimum (1)")
	}

	// check the maximum slowTimePeriod
	if signalTimePeriod > MaximumLookbackPeriod {
		return nil, errors.New("signalTimePeriod is greater than the maximum (100000)")
	}

	if selectData == nil {
		return nil, ErrDOHLCVDataSelectFuncIsNil
	}

	lookback := slowTimePeriod + signalTimePeriod - 2
	ind := Macd{
		baseIndicator:    newBaseIndicator(lookback),
		baseFloatBounds:  newBaseFloatBounds(),
		fastTimePeriod:   fastTimePeriod,
		slowTimePeriod:   slowTimePeriod,
		signalTimePeriod: signalTimePeriod,
	}

	// shift the fast ema up so that it has valid data at the same time as the slow emas
	ind.emaSlowSkip = slowTimePeriod - fastTimePeriod
	ind.emaFast, err = NewEmaWithoutStorage(fastTimePeriod, func(dataItem float64, streamBarIndex int) {
		ind.currentFastEma = dataItem
	})

	ind.emaSlow, err = NewEmaWithoutStorage(slowTimePeriod, func(dataItem float64, streamBarIndex int) {
		ind.currentSlowEma = dataItem

		ind.currentMacd = ind.currentFastEma - ind.currentSlowEma

		ind.emaSignal.ReceiveTick(ind.currentMacd, streamBarIndex)
	})

	ind.emaSignal, err = NewEmaWithoutStorage(signalTimePeriod, func(dataItem float64, streamBarIndex int) {

		// Macd Line: (12-day EmaWithoutStorage - 26-day EmaWithoutStorage)

		// Signal Line: 9-day EmaWithoutStorage of Macd Line

		// Macd Histogram: Macd Line - Signal Line

		macd := ind.currentFastEma - ind.currentSlowEma
		signal := dataItem
		histogram := macd - signal

		ind.UpdateMinMax(macd, macd)
		ind.UpdateMinMax(signal, signal)
		ind.UpdateMinMax(histogram, histogram)

		ind.IncDataLength()

		ind.SetValidFromBar(streamBarIndex)

		// notify of a new result value though the value available action
		ind.valueAvailableAction(macd, signal, histogram, streamBarIndex)
	})

	ind.selectData = selectData
	ind.valueAvailableAction = func(dataItemMacd float64, dataItemSignal float64, dataItemHistogram float64, streamBarIndex int) {
		ind.Macd = append(ind.Macd, dataItemMacd)
		ind.Signal = append(ind.Signal, dataItemSignal)
		ind.Histogram = append(ind.Histogram, dataItemHistogram)
	}
	return &ind, err
}
431913
func newNodeDB(path string, version int, self NodeID) (*nodeDB, error) {
	if path == "" {
		return newMemoryNodeDB(self)
	}
	return newPersistentNodeDB(path, version, self)
}
112882
func NewMacro(indent, alias string, master, trailing bool, evaluator ParamEvaluator) *Macro {
	return &Macro{
		indent:   indent,
		alias:    alias,
		master:   master,
		trailing: trailing,

		Evaluator: evaluator,
	}
}
1114604
func (s *Service) CreateMacro(ctx context.Context, m *platform.Macro) error {
	op := OpPrefix + platform.OpCreateMacro
	m.ID = s.IDGenerator.ID()
	err := s.ReplaceMacro(ctx, m)
	if err != nil {
		return &platform.Error{
			Op:  op,
			Err: err,
		}
	}
	return nil
}
683666
func NewDiscoverdNodes(data []byte) (*DiscoverdNodes, error) {
	f := &DiscoverdNodes{
		data: data,
	}

	if len(data) < 6 {
		return nil, fmt.Errorf("wrong length, should be at least 6 bytes got %d", len(data))
	}

	for index, bits := range data {
		f.ActiveNodes[index*8+0] = bits&0x01 != 0
		f.ActiveNodes[index*8+1] = bits&0x02 != 0
		f.ActiveNodes[index*8+2] = bits&0x04 != 0
		f.ActiveNodes[index*8+3] = bits&0x08 != 0

		f.ActiveNodes[index*8+4] = bits&0x10 != 0
		f.ActiveNodes[index*8+5] = bits&0x20 != 0
		f.ActiveNodes[index*8+6] = bits&0x40 != 0
		f.ActiveNodes[index*8+7] = bits&0x80 != 0
	}

	return f, nil
}
1066
func newNode(cluster *Cluster, nv *nodeValidator) *Node {
	newNode := &Node{
		cluster: cluster,
		name:    nv.name,
		// address: nv.primaryAddress,
		host: nv.primaryHost,

		// Assign host to first IP alias because the server identifies nodes
		// by IP address (not hostname).
		connections:         *newConnectionHeap(cluster.clientPolicy.ConnectionQueueSize),
		connectionCount:     *NewAtomicInt(0),
		peersGeneration:     *NewAtomicInt(-1),
		partitionGeneration: *NewAtomicInt(-2),
		referenceCount:      *NewAtomicInt(0),
		failures:            *NewAtomicInt(0),
		active:              *NewAtomicBool(true),
		partitionChanged:    *NewAtomicBool(false),

		supportsFloat:             *NewAtomicBool(nv.supportsFloat),
		supportsBatchIndex:        *NewAtomicBool(nv.supportsBatchIndex),
		supportsReplicas:          *NewAtomicBool(nv.supportsReplicas),
		supportsGeo:               *NewAtomicBool(nv.supportsGeo),
		supportsPeers:             *NewAtomicBool(nv.supportsPeers),
		supportsLUTNow:            *NewAtomicBool(nv.supportsLUTNow),
		supportsTruncateNamespace: *NewAtomicBool(nv.supportsTruncateNamespace),
	}

	newNode.aliases.Store(nv.aliases)
	newNode._sessionToken.Store(nv.sessionToken)
	newNode.racks.Store(map[string]int{})

	// this will reset to zero on first aggregation on the cluster,
	// therefore will only be counted once.
	atomic.AddInt64(&newNode.stats.NodeAdded, 1)

	return newNode
}
1312226
func NewCpCode(parent *CpCodes) *CpCode {
	cpcode := &CpCode{parent: parent}
	cpcode.Init()
	return cpcode
}
374339
func (tn *tagNode) appendRawNode(raw string) *rawNode {
	nrn := newRawNode(raw)
	tn.appendChild(nrn)
	return nrn
}
959217
func newOperatorNode(op string, left, right node) node {
	return &operatorNode{nodeType: nodeOperator, Op: op, Left: left, Right: right}
}
537604
func NewNode(t *Type, id *ID) *Node {
	return &Node{
		t:  t,
		id: id,
	}
}
1184314
func NewNode(nodePtr unsafe.Pointer, document Document) (node Node) {
	if nodePtr == nil {
		return nil
	}
	xmlNode := &XmlNode{
		Ptr:      (*C.xmlNode)(nodePtr),
		Document: document,
		valid:    true,
	}
	nodeType := NodeType(C.getNodeType((*C.xmlNode)(nodePtr)))

	switch nodeType {
	default:
		node = xmlNode
	case XML_ATTRIBUTE_NODE:
		node = &AttributeNode{XmlNode: xmlNode}
	case XML_ELEMENT_NODE:
		node = &ElementNode{XmlNode: xmlNode}
	case XML_CDATA_SECTION_NODE:
		node = &CDataNode{XmlNode: xmlNode}
	case XML_COMMENT_NODE:
		node = &CommentNode{XmlNode: xmlNode}
	case XML_PI_NODE:
		node = &ProcessingInstructionNode{XmlNode: xmlNode}
	case XML_TEXT_NODE:
		node = &TextNode{XmlNode: xmlNode}
	}
	return
}