public bool FindNextKey(List<NodeIdxPair> stack)
{
int idx = stack.Count - 1;
while (idx >= 0)
{
var pair = stack[idx];
if (pair.Node.NextIdxValid(pair.Idx))
{
stack.RemoveRange(idx + 1, stack.Count - idx - 1);
stack[idx] = new NodeIdxPair { Node = pair.Node, Idx = pair.Idx + 1 };
pair.Node.FillStackByLeftMost(stack, pair.Idx + 1);
return true;
}
idx--;
}
return false;
}