A small menubar app that allows you to switch between R versions quickly (if you have multiple versions of R framework installed).
https://rud.is/rswitch
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.1 KiB
51 lines
1.1 KiB
5 years ago
|
//
|
||
|
// NodeTraversor.swift
|
||
|
// SwiftSoup
|
||
|
//
|
||
|
// Created by Nabil Chatbi on 17/10/16.
|
||
|
// Copyright © 2016 Nabil Chatbi.. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import Foundation
|
||
|
|
||
|
class NodeTraversor {
|
||
|
private let visitor: NodeVisitor
|
||
|
|
||
|
/**
|
||
|
* Create a new traversor.
|
||
|
* @param visitor a class implementing the {@link NodeVisitor} interface, to be called when visiting each node.
|
||
|
*/
|
||
|
public init(_ visitor: NodeVisitor) {
|
||
|
self.visitor = visitor
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Start a depth-first traverse of the root and all of its descendants.
|
||
|
* @param root the root node point to traverse.
|
||
|
*/
|
||
|
open func traverse(_ root: Node?)throws {
|
||
|
var node: Node? = root
|
||
|
var depth: Int = 0
|
||
|
|
||
|
while (node != nil) {
|
||
|
try visitor.head(node!, depth)
|
||
|
if (node!.childNodeSize() > 0) {
|
||
|
node = node!.childNode(0)
|
||
|
depth+=1
|
||
|
} else {
|
||
|
while (node!.nextSibling() == nil && depth > 0) {
|
||
|
try visitor.tail(node!, depth)
|
||
|
node = node!.getParentNode()
|
||
|
depth-=1
|
||
|
}
|
||
|
try visitor.tail(node!, depth)
|
||
|
if (node === root) {
|
||
|
break
|
||
|
}
|
||
|
node = node!.nextSibling()
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|