// NewNode converts the given data into a node.
497826
func NewNode(key string, data interface{}) *Node {
	n := &Node{
		Key: key,
	}

	n.mtx.Lock()
	n.Children = map[string]*Node{}
	n.mtx.Unlock()

	if data == nil {
		return n
	}

	switch val := reflect.ValueOf(data); val.Kind() {
	case reflect.Map:
		for _, k := range val.MapKeys() {
			v := val.MapIndex(k)
			key := fmt.Sprintf("%s", k.Interface())

			child := NewNode(key, v.Interface())
			child.Parent = n
			n.Children[key] = child
		}

	case reflect.Array, reflect.Slice:
		n.sliceKids = true

		for i := 0; i < val.Len(); i++ {
			v := val.Index(i)
			key := strconv.FormatInt(int64(i), 10)

			child := NewNode(key, v.Interface())
			child.Parent = n
			n.Children[key] = child
		}

	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		fallthrough
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
		fallthrough
	case reflect.Float32, reflect.Float64:
		fallthrough
	case reflect.String, reflect.Bool, reflect.Interface:
		n.Value = val.Interface()
	default:
		fmt.Printf("Unsupported type %s(%#v)If you see this log please report an issue on https://github.com/zabawaba99/firego", data, data)
	}

	return n
}
1331097
func NewNode(id NodeID, ip net.IP, udpPort, tcpPort uint16) *Node {
	if ipv4 := ip.To4(); ipv4 != nil {
		ip = ipv4
	}
	return &Node{
		IP:          ip,
		UDP:         udpPort,
		TCP:         tcpPort,
		ID:          id,
		nodeNetGuts: nodeNetGuts{sha: crypto.Keccak256Hash(id[:])},
	}
}
1365036
func newFunctionNode(name, prefix string, args []node) node {
	return &functionNode{nodeType: nodeFunction, Prefix: prefix, FuncName: name, Args: args}
}
204314
func (b *PositionBuilder) NewNodePosition(n node.Node) *position.Position {
	return &position.Position{
		StartLine: b.getNodeStartPos(n).startLine,
		EndLine:   b.getNodeEndPos(n).endLine,
		StartPos:  b.getNodeStartPos(n).startPos,
		EndPos:    b.getNodeEndPos(n).endPos,
	}
}
639275
func (b *PositionBuilder) NewNodesPosition(startNode node.Node, endNode node.Node) *position.Position {
	return &position.Position{
		StartLine: b.getNodeStartPos(startNode).startLine,
		EndLine:   b.getNodeEndPos(endNode).endLine,
		StartPos:  b.getNodeStartPos(startNode).startPos,
		EndPos:    b.getNodeEndPos(endNode).endPos,
	}
}
837513
func NewNode(ctx context.Context, cfg *BuildCfg) (*IpfsNode, error) {
	if cfg == nil {
		cfg = new(BuildCfg)
	}

	err := cfg.fillDefaults()
	if err != nil {
		return nil, err
	}

	ctx = metrics.CtxScope(ctx, "ipfs")

	n := &IpfsNode{
		IsOnline:  cfg.Online,
		Repo:      cfg.Repo,
		ctx:       ctx,
		Peerstore: pstoremem.NewPeerstore(),
	}

	n.RecordValidator = record.NamespacedValidator{
		"pk":   record.PublicKeyValidator{},
		"ipns": ipns.Validator{KeyBook: n.Peerstore},
	}

	// TODO: this is a weird circular-ish dependency, rework it
	n.proc = goprocessctx.WithContextAndTeardown(ctx, n.teardown)

	if err := setupNode(ctx, n, cfg); err != nil {
		n.Close()
		return nil, err
	}

	return n, nil
}
74723
func NewIfNode(cond Expr, body Node, els Node, p Pos) *IfNode {
	return &IfNode{p, TrimmableNode{}, cond, body, els}
}
1369083
func NewNode() *ConfigDataNode {
	return &ConfigDataNode{
		mutex: new(sync.Mutex),
		table: make(map[string]ctypes.ConfigValue),
	}
}
307039
func newFilterNode(n, m node) node {
	return &filterNode{nodeType: nodeFilter, Input: n, Condition: m}
}
249465
func newVariableNode(prefix, name string) node {
	return &variableNode{nodeType: nodeVariable, Name: name, Prefix: prefix}
}
959217
func newOperatorNode(op string, left, right node) node {
	return &operatorNode{nodeType: nodeOperator, Op: op, Left: left, Right: right}
}
1024037
func (c *Calcium) AddNode(ctx context.Context, nodename, endpoint, podname, ca, cert, key string, cpu, share int, memory int64, labels map[string]string) (*types.Node, error) {
	return c.store.AddNode(ctx, nodename, endpoint, podname, ca, cert, key, cpu, share, memory, labels)
}
441731
func NewClientNode(cm *ClientManager, params ServerParams) *ClientNode {
	node := &ClientNode{
		cm:       cm,
		params:   params,
		bufValue: params.BufLimit,
		lastTime: cm.clock.Now(),
		accepted: make(map[uint64]uint64),
	}
	if keepLogs > 0 {
		node.log = newLogger(keepLogs)
	}
	cm.connect(node)
	return node
}
60364
func (c *client) NodeCreate(in *Node) (*Node, error) {
	out := new(Node)
	uri := fmt.Sprintf(pathNodes, c.addr)
	err := c.post(uri, in, out)
	return out, err
}
1151849
func NewRestNode() *RestNode {
	return &RestNode{
		Res:          make(map[string]*restObj),
		ResUdid:      make(map[string]*restObjUdid),
		Children:     make(map[string]*RestNode),
		ChildrenUdid: make(map[string]*RestNode),
	}
}
1299327
func newNode(index int, parent *node, hasher hash.Hash) *node {
	return &node{
		parent: parent,
		isLeft: index%2 == 0,
		hasher: hasher,
	}
}
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
}