Cache tree's standard Pre-Order Traversal
433027
protected function loadRawOrder($tmpSubTier)
    {
        $nID = $tmpSubTier[0];
        $this->nodesRawIndex[$nID] = sizeof($this->nodesRawOrder);
        $this->nodesRawOrder[] = $nID;
        if (sizeof($tmpSubTier[1]) > 0) {
            foreach ($tmpSubTier[1] as $deeper) {
                $this->loadRawOrder($deeper);
            }
        }
        return true;
    }
128699
private void traverse(GroovySourceAST t,List l,Iterator itr) {
         while (t != null) {
             // first visit of node
             if (l != null) {
                 l.add(new LineColumn(t.getLine(),t.getColumn()));
             }

             // second visit of node
             if (itr != null && itr.hasNext()) {
                 LineColumn lc = (LineColumn)itr.next();
                 if (t.getLineLast() == 0) {
                     int nextLine = lc.getLine();
                     int nextColumn = lc.getColumn();
                     if (nextLine < t.getLine() || (nextLine == t.getLine() && nextColumn < t.getColumn())) {
                         nextLine = t.getLine();
                         nextColumn = t.getColumn();
                     }
                     t.setLineLast(nextLine);
                     t.setColumnLast(nextColumn);
                     // This is a good point to call t.setSnippet(),
                     // but it bulks up the AST too much for production code.
                 }
             }

             GroovySourceAST child = (GroovySourceAST)t.getFirstChild();
             if (child != null) {
                 traverse(child,l,itr);
             }

             t = (GroovySourceAST)t.getNextSibling();
         }
    }
1030875
def _iter_descendants_preorder(self, is_leaf_fn=None):
        
        to_visit = deque()
        node = self
        while node is not None:
            yield node
            if not is_leaf_fn or not is_leaf_fn(node):
                to_visit.extendleft(reversed(node.children))
            try:
                node = to_visit.popleft()
            except:
                node = None
905629
private LinkedList<T> computeRecursiveTraversal(T node, NodePath<T> nodePath) {
    try {


      LinkedList<T> imports = new LinkedList<>();
      Set<T> alreadyIncludedImports = new HashSet<>();

      for (T neighbor : this.traversalFunction.apply(node)) {
        nodePath.appendNode(neighbor);
        addSubtraversal(neighbor, imports, alreadyIncludedImports, nodePath);
        nodePath.popTail();
      }

      return imports;
    } catch (ExecutionException ee) {
      throw new RuntimeException(ee);
    }
  }
1174127
function getCachedFrame (node, cacheKey, delegateFn, Sequence) {
  let cacheEntry = cache[cacheKey];

  if (cacheEntry && cacheEntry.compressed) {
    // Once a cache entry has been completely evaluated and compressed, it is no longer
    // necessary to patch the original sequence.  Instead, simply emit the cached
    // segments onto the original sequence.
    return {
      patch: originalSequence => {
        cacheEntry.segments.forEach(segment => originalSequence.emit(() => segment));
      }
    };
  }

  if (!cacheEntry) {
    const onCompress = buffer => {
      cache[cacheKey] = {
        compressed: true,
        // Remove the EXHAUSTED symbol from the end;
        segments: buffer.slice(0, -1)
      };
    };

    const seq = new Sequence();
    delegateFn(seq, node);

    cacheEntry = cache[cacheKey] = new FrameCache(onCompress, seq);
  }

  return cacheEntry.fork();
}
884331
function getPrev(renderTree) {

    if (!renderTree || !renderTree.children || renderTree.children.length < 1
        || !renderTree.children[renderTree.children.length - 1]) {
        return;
    }

    return renderTree.children[renderTree.children.length - 1];

}
1347670
function(dt, inc) {
        var args = {
                dt: dt,
                inc: inc
            },
            result = this._cacheGet('before', args);
        if (result === false) {
            result = this._iter(new IterResult('before', args));
            this._cacheAdd('before', result, args);
        }
        return result;
    }
220044
def cached(key, path_info, details, locals)
      name, prefix, partial = path_info

      if key
        @cache.cache(key, name, prefix, partial, locals) do
          yield
        end
      else
        yield
      end
    end
978155
function preCacheQueries(queries) {
  var groupBy = {};
  _.each(queries, function (query) {
    if (!query.queryKey) {
      return;
    }
    var hasAllValues = _.reduce(_.values(query.queryParams), function (acc, val) {
      return acc && (val !== null);
    }, true);
    if (hasAllValues) {
      var cacheKey = _executionCache.getKey(query);
      groupBy[cacheKey] = groupBy[cacheKey] || [];
      groupBy[cacheKey].push(query);
    }
  });

  _.each(groupBy, function (groupedQueries, key) {
    var aggregateShape = _.reduce(_.map(groupedQueries, 'shape'), _.assign, {});
    var query = _.cloneDeep(groupedQueries[0]);
    query.shape = aggregateShape;
    _executionCache.execute(query);
  });
}
368430
def traverse c, &block
      if c.is_a? BaseStack
        yield c
        c.components.each { |e| 
          yield e
        }
        c.components.each { |e| traverse(e, &block)  }
        @ctr -= 1
      else
      end
    end
66272
def traverse_until_fixpoint(predicate, tree):
    """"""
    old_tree = None
    tree = simplify(tree)
    while tree and old_tree != tree:
        old_tree = tree
        tree = tree.traverse(predicate)
        if not tree:
            return None
        tree = simplify(tree)
    return tree
479396
function traverse(object, visitor) {
  let child;
  if (!object) return;

  let r = visitor.call(null, object);
  if (r === STOP) return STOP; // stop whole traverse immediately
  if (r === SKIP_BRANCH) return; // skip going into AST branch

  for (let i = 0, keys = Object.keys(object); i < keys.length; i++) {
    let key = keys[i];
    if (IGNORED_KEYS.indexOf(key) !== -1) continue;

    child = object[key];
    if (typeof child === 'object' && child !== null) {
      if (traverse(child, visitor) === STOP) {
        return STOP;
      }
    }
  }
}
104567
def bsp_traverse_level_order(
    node: tcod.bsp.BSP,
    callback: Callable[[tcod.bsp.BSP, Any], None],
    userData: Any = 0,
) -> None:
    
    _bsp_traverse(node.level_order(), callback, userData)
392999
private int gatherInfo(LblTree aT, int postorder) {
		int currentSize = 0;
		int childrenCount = 0;
		int descSizes = 0;
		int krSizesSum = 0;
		int revkrSizesSum = 0;
		int preorder = preorderTmp;

		int heavyChild = -1;
		int leftChild = -1;
		int rightChild = -1;
		int weight = -1;
		int maxWeight = -1;
		int currentPostorder = -1;
		int oldHeavyChild = -1;

		ArrayList<Integer> heavyRelSubtreesTmp = new ArrayList<>();
		ArrayList<Integer> leftRelSubtreesTmp = new ArrayList<>();
		ArrayList<Integer> rightRelSubtreesTmp = new ArrayList<>();

		ArrayList<Integer> childrenPostorders = new ArrayList<>();

		preorderTmp++;

		// enumerate over children of current node
		for (Enumeration<?> e = aT.children(); e.hasMoreElements(); ) {
			childrenCount++;

			postorder = gatherInfo((LblTree) e.nextElement(), postorder);

			childrenPostorders.add(postorder);

			currentPostorder = postorder;

			// heavy path
			weight = sizeTmp + 1;
			if (weight >= maxWeight) {
				maxWeight = weight;
				oldHeavyChild = heavyChild;
				heavyChild = currentPostorder;
			} else {
				heavyRelSubtreesTmp.add(currentPostorder);
			}
			if (oldHeavyChild != -1) {
				heavyRelSubtreesTmp.add(oldHeavyChild);
				oldHeavyChild = -1;
			}

			// left path
			if (childrenCount == 1) {
				leftChild = currentPostorder;
			} else {
				leftRelSubtreesTmp.add(currentPostorder);
			}

			// right path
			rightChild = currentPostorder;
			if (e.hasMoreElements()) {
				rightRelSubtreesTmp.add(currentPostorder);
			}

			// subtree size
			currentSize += 1 + sizeTmp;

			descSizes += descSizesTmp;

			if (childrenCount > 1) {
				krSizesSum += krSizesSumTmp + sizeTmp + 1;
			} else {
				krSizesSum += krSizesSumTmp;
				nodeType[LEFT][currentPostorder] = true;
			}

			if (e.hasMoreElements()) {
				revkrSizesSum += revkrSizesSumTmp + sizeTmp + 1;
			} else {
				revkrSizesSum += revkrSizesSumTmp;
				nodeType[RIGHT][currentPostorder] = true;
			}
		}

		postorder++;

		// postorder
		aT.setTmpData(postorder);

		int currentDescSizes = descSizes + currentSize + 1;
		info[POST2_DESC_SUM][postorder] =
				(currentSize + 1) * (currentSize + 1 + 3) / 2 - currentDescSizes;
		info[POST2_KR_SUM][postorder] = krSizesSum + currentSize + 1;
		info[POST2_REV_KR_SUM][postorder] = revkrSizesSum + currentSize + 1;

		// POST2_LABEL
		// labels[rootNumber] = ld.store(aT.getLabel());
		info[POST2_LABEL][postorder] = ld.store(aT.getLabel());

		// POST2_PARENT
		for (Integer i : childrenPostorders) {
			info[POST2_PARENT][i] = postorder;
		}

		// POST2_SIZE
		info[POST2_SIZE][postorder] = currentSize + 1;
		if (currentSize == 0) {
			leafCount++;
		}

		// POST2_PRE
		info[POST2_PRE][postorder] = preorder;

		// PRE2_POST
		info[PRE2_POST][preorder] = postorder;

		// RPOST2_POST
		info[RPOST2_POST][treeSize - 1 - preorder] = postorder;

		// heavy path
		if (heavyChild != -1) {
			paths[HEAVY][postorder] = heavyChild;
			nodeType[HEAVY][heavyChild] = true;

			if (leftChild < heavyChild && heavyChild < rightChild) {
				info[POST2_STRATEGY][postorder] = BOTH;
			} else if (heavyChild == leftChild) {
				info[POST2_STRATEGY][postorder] = RIGHT;
			} else if (heavyChild == rightChild) {
				info[POST2_STRATEGY][postorder] = LEFT;
			}
		} else {
			info[POST2_STRATEGY][postorder] = RIGHT;
		}

		// left path
		if (leftChild != -1) {
			paths[LEFT][postorder] = leftChild;
		}
		// right path
		if (rightChild != -1) {
			paths[RIGHT][postorder] = rightChild;
		}

		// heavy/left/right relevant subtrees
		relSubtrees[HEAVY][postorder] = toIntArray(heavyRelSubtreesTmp);
		relSubtrees[RIGHT][postorder] = toIntArray(rightRelSubtreesTmp);
		relSubtrees[LEFT][postorder] = toIntArray(leftRelSubtreesTmp);

		descSizesTmp = currentDescSizes;
		sizeTmp = currentSize;
		krSizesSumTmp = krSizesSum;
		revkrSizesSumTmp = revkrSizesSum;

		return postorder;
	}
457968
function traverseDepthFirstSync(rootNode, options) {
  options = extend({
    subnodesAccessor: function(node) { return node.subnodes; },
    userdataAccessor: function(node, userdata) { return userdata; },
    onNode: function(node, userdata) {},
    userdata: null
  }, options);

  var stack = [];
  stack.push([rootNode, options.userdata]);
  while (stack.length>0) {
    var top = stack.pop();
    var node = top[0];
    var data = top[1];

    options.onNode(node, data);

    var subnodeData = options.userdataAccessor(node, data);
    var subnodes = options.subnodesAccessor(node);
    for (var i=0; i<subnodes.length; i++)
      stack.push([subnodes[i], subnodeData]);
  }
  return rootNode;
}
213715
function (listItemContainers, node) {
        var isOrdered = node.nodeName === 'OL';
        var startIndex = parseInt(node.getAttribute('start'), 10) || 1; // only applicable to ordered lists
        var blocks = (listItemContainers || []).map((listItemContainer, listItemIndex) => {
            var listItemElems = unwrap(listItemContainer);
            var firstListItemElem = listItemElems[0];
            if (firstListItemElem && isTextBlock(firstListItemElem)) {
                let firstListItemPrefix = isOrdered ? `${startIndex + listItemIndex}. ` : `- `;
                firstListItemElem.text = firstListItemPrefix + firstListItemElem.text;
            }
            return listItemElems;
        }).reduce((prevBlocks, listItemBlocks) => {
            return prevBlocks.concat(listItemBlocks);
        }, []);
        return wrap(blocks);
    }
780780
def bsp_traverse_inverted_level_order(
    node: tcod.bsp.BSP,
    callback: Callable[[tcod.bsp.BSP, Any], None],
    userData: Any = 0,
) -> None:
    
    _bsp_traverse(node.inverted_level_order(), callback, userData)