geotrellis / maml

Map Algebra Modeling Language: It's what we and whales are.
https://geotrellis.github.io/maml/
Apache License 2.0
16 stars 10 forks source link

Tree node identity #6

Open moradology opened 7 years ago

moradology commented 7 years ago

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 commented 6 years ago

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)
    }
  }
}