// NewTreeNode creates a TreeNode with given path and parent.
// NOTE: parent should be nil if the node is root.
765126
func NewTreeNode(tree *TreeCache, path string, parent *TreeNode) *TreeNode {
	depth := 0
	if parent != nil {
		depth = parent.depth + 1
	}
	return &TreeNode{
		tree:     tree,
		state:    NodeStatePENDING,
		parent:   parent,
		path:     path,
		children: make(map[string]*TreeNode),
		depth:    depth,
	}
}
893765
func (c *ChannelGraph) SetSourceNode(node *LightningNode) error {
	nodePubBytes := node.PubKeyBytes[:]

	return c.db.Update(func(tx *bbolt.Tx) error {
		// First grab the nodes bucket which stores the mapping from
		// pubKey to node information.
		nodes, err := tx.CreateBucketIfNotExists(nodeBucket)
		if err != nil {
			return err
		}

		// Next we create the mapping from source to the targeted
		// public key.
		if err := nodes.Put(sourceKey, nodePubBytes); err != nil {
			return err
		}

		// Finally, we commit the information of the lightning node
		// itself.
		return addLightningNode(tx, node)
	})
}
116260
func NewTrnType(s string) (trnType, error) {
	var e trnType
	err := e.FromString(s)
	if err != nil {
		return 0, err
	}
	return e, nil
}
814627
func EnsureRouteNode(g osgraph.MutableUniqueGraph, route *routev1.Route) *RouteNode {
	return osgraph.EnsureUnique(
		g,
		RouteNodeName(route),
		func(node osgraph.Node) graph.Node {
			return &RouteNode{
				Node:  node,
				Route: route,
			}
		},
	).(*RouteNode)
}
1281206
func (n *NodeApplyableModuleVariable) EvalTree() EvalNode {
	// If we have no value, do nothing
	if n.Expr == nil {
		return &EvalNoop{}
	}

	// Otherwise, interpolate the value of this variable and set it
	// within the variables mapping.
	vals := make(map[string]cty.Value)

	_, call := n.Addr.Module.CallInstance()

	return &EvalSequence{
		Nodes: []EvalNode{
			&EvalOpFilter{
				Ops: []walkOperation{walkRefresh, walkPlan, walkApply,
					walkDestroy, walkValidate},
				Node: &EvalModuleCallArgument{
					Addr:   n.Addr.Variable,
					Config: n.Config,
					Expr:   n.Expr,
					Values: vals,

					IgnoreDiagnostics: false,
				},
			},

			&EvalSetModuleCallArguments{
				Module: call,
				Values: vals,
			},
		},
	}
}
682545
func (node *Node) PathToLeaf(t *ImmutableTree, key []byte) (PathToLeaf, *Node, error) {
	path := new(PathToLeaf)
	val, err := node.pathToLeaf(t, key, path)
	return *path, val, err
}
328426
func NewTree(preallocate int) *Tree {
	tree := new(Tree)
	tree.root = tree.newnode()
	if preallocate == 0 {
		return tree
	}

	// Simplification, static preallocate max 6 bits
	if preallocate > 6 || preallocate < 0 {
		preallocate = 6
	}

	var key, mask uint32

	for inc := startbit; preallocate > 0; inc, preallocate = inc>>1, preallocate-1 {
		key = 0
		mask >>= 1
		mask |= startbit

		for {
			tree.insert32(key, mask, nil, false)
			key += inc
			if key == 0 { // magic bits collide
				break
			}
		}
	}

	return tree
}
548386
func (p Path) GetDirNode(ctx context.Context, config libkbfs.Config) (libkbfs.Node, error) {
	// TODO: Handle non-TLFPathTypes.

	n, de, err := p.GetNode(ctx, config)
	if err != nil {
		return nil, err
	}

	// TODO: What to do with symlinks?

	if de.Type != data.Dir {
		return nil, fmt.Errorf("openDir: %s is not a dir, but a %s", p, de.Type)
	}

	return n, nil
}
597275
func (document *XmlDocument) Root() (element *ElementNode) {
	nodePtr := C.xmlDocGetRootElement(document.Ptr)
	if nodePtr != nil {
		element = NewNode(unsafe.Pointer(nodePtr), document).(*ElementNode)
	}
	return
}
1299659
func (r *randomGraph) newTriple(i, j int) (*triple.Triple, error) {
	s, err := r.newNode(i)
	if err != nil {
		return nil, err
	}
	o, err := r.newNode(j)
	if err != nil {
		return nil, err
	}
	return triple.New(s, r.predicate, triple.NewNodeObject(o))
}
636360
func (xmlNode *XmlNode) Parent() Node {
	if C.xmlNodePtrCheck(unsafe.Pointer(xmlNode.Ptr.parent)) == C.int(0) {
		return nil
	}
	return NewNode(unsafe.Pointer(xmlNode.Ptr.parent), xmlNode.Document)
}
838317
func (b *PositionBuilder) NewTokenNodeListPosition(t *scanner.Token, list []node.Node) *position.Position {
	return &position.Position{
		StartLine: t.StartLine,
		EndLine:   b.getListEndPos(list).endLine,
		StartPos:  t.StartPos,
		EndPos:    b.getListEndPos(list).endPos,
	}
}
908203
func ParseNode(s string) (node Node, err error) {
	s = strings.TrimSpace(s)
	if s == "" {
		return Node{}, ErrInvalidNode
	}

	if !strings.Contains(s, "://") {
		s = "auto://" + s
	}
	u, err := url.Parse(s)
	if err != nil {
		return
	}

	node = Node{
		Addr:   u.Host,
		Host:   u.Host,
		Remote: strings.Trim(u.EscapedPath(), "/"),
		Values: u.Query(),
		User:   u.User,
		marker: &failMarker{},
		url:    u,
	}

	u.RawQuery = ""
	u.User = nil

	schemes := strings.Split(u.Scheme, "+")
	if len(schemes) == 1 {
		node.Protocol = schemes[0]
		node.Transport = schemes[0]
	}
	if len(schemes) == 2 {
		node.Protocol = schemes[0]
		node.Transport = schemes[1]
	}

	switch node.Transport {
	case "tls", "mtls", "ws", "mws", "wss", "mwss", "kcp", "ssh", "quic", "ssu", "http2", "h2", "h2c", "obfs4":
	case "https":
		node.Protocol = "http"
		node.Transport = "tls"
	case "tcp", "udp": // started from v2.1, tcp and udp are for local port forwarding
	case "rtcp", "rudp": // rtcp and rudp are for remote port forwarding
	case "ohttp": // obfs-http
	default:
		node.Transport = "tcp"
	}

	switch node.Protocol {
	case "http", "http2", "socks4", "socks4a", "ss", "ssu", "sni":
	case "socks", "socks5":
		node.Protocol = "socks5"
	case "tcp", "udp", "rtcp", "rudp": // port forwarding
	case "direct", "remote", "forward": // forwarding
	case "redirect": // TCP transparent proxy
	default:
		node.Protocol = ""
	}

	return
}
944446
func (n *Node) getRootNode() *Node {
	if n.parent == nil {
		return n
	}
	return n.parent.getRootNode()
}
782909
func ConvertToNode(obj interface{}) interface{} {
	node, ok := obj.(*v1.Node)
	if !ok {
		return nil
	}
	n := &types.Node{
		TypeMeta:        node.TypeMeta,
		ObjectMeta:      node.ObjectMeta,
		StatusAddresses: node.Status.Addresses,
		SpecPodCIDR:     node.Spec.PodCIDR,
	}
	*node = v1.Node{}
	return n
}
426002
func Mknod(path string, mode uint32, dev int) error {
	return unix.Mknod(path, mode, dev)
}
292732
func (t *T) TempDirMode(mode os.FileMode) string {
	f, err := ioutilTempDir(t.RootTempDir(), t.Name())
	t.ExpectSuccess(err)
	t.NotEqual(f, "")
	t.ExpectSuccess(osChmod(f, mode))
	t.AddFinalizer(func() {
		osRemoveAll(f)
	})
	return f
}