Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree node identity #6

Open
moradology opened this issue Aug 8, 2017 · 1 comment
Open

Tree node identity #6

moradology opened this issue Aug 8, 2017 · 1 comment
Labels

Comments

@moradology
Copy link
Contributor

In RFML, we've used UUIDs that get associated with a node for the ID of that node. We should either trim that down (associate an Int with a node instead) or be able to (repeatably) generate a unique set of IDs in some fashion for a given tree

@moradology
Copy link
Contributor Author

moradology commented Sep 27, 2017

The current thinking on this is to provide - via a very simple algorithm - a means of identifying nodes. This way the client and server can pass information back and forth about portions of the tree without passing indexes around in a JSON structure that we'd like to keep as thin as possible. Perhaps:

trait AST {
var id: Option[Int]

def identify(ast: AST): AST = {
  var count = 0
  def eval(ast: AST): AST = {
    val thisId = Some(count)
    count = count + 1
    ast match {
      case l: LeafNode =>
        l.withId(thisId)
      case b: BranchNode =>
        val children = b.args.map(eval)
        b.withId(thisId).withChildren(children)
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant