code: function addNode(parent, node, order, contexts) {
      var length = contexts.length;
      var index, context;
      var children, childrenLength, child;
      var targetContext, insertionIndex;
      var childFound = false;
  
      while (length--) {
          context = contexts[length];
  
          // No need to keep searching contexts for this node if it has already been found.
          if (!childFound) {
              children = context.children;
              childrenLength = children.length;
  
              while (childrenLength--) {
                  child = children[childrenLength];
  
                  // Check to see if this node was previously added to a context.
                  if (child.node === node) {
                      children.splice(childrenLength, 1);
                      childFound = true;
                      break;
                  }
              }
          }
  
          if (context.parent === parent) {
              targetContext = context;
  
              // If we found the context AND the child, there is no need to keep looping.
              if (childFound) { break; }
          }
      }
  
      // No context for this parent node was found. Create one.
      if (!targetContext) {
          targetContext = {
              parent: parent,
              children: []
          };
  
          contexts.push(targetContext);
      }
  
      // Insert the child in the correct spot based on its order.
      children = targetContext.children;
      length = children.length;
      insertionIndex = length; // Insert at the end by default.
      for (index = 0; index < length; index++) {
          child = children[index];
  
          if (order < child.order) {
              // If my order is less than this child's, take its spot.
              insertionIndex = index;
              break;
          }
      }
  
      children.splice(insertionIndex, 0, {
          order: order,
          node: node
      });
  }
docs: /*
  This Function adds a Node to a given context Object (by adding an entry to its children Array.)
  The child is inserted in the Array such that the children are sorted based on "order"
  (descending.) If an entry for a child Node already exists, the existing entry is removed.