You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: commitnode_walker_topo_order.go
    path of file: ./repos/go-git/plumbing/object/commitgraph
    
    the code of the file until where you have to start completion: package commitgraph

import (
	"io"

	"github.com/go-git/go-git/v5/plumbing"
	"github.com/go-git/go-git/v5/plumbing/storer"

	"github.com/emirpasic/gods/trees/binaryheap"
)

type commitN
    
func (iter *commitNodeIteratorTopological) Next() (CommitNode, error) {
	var next CommitNode
	for {
		var ok bool
		next, ok = iter.visitStack.Pop()
		if !ok {
			return nil, io.EOF
		}

		if iter.inCounts[next.ID()] == 0 {
			break
		}
	}

	minimumLevel, generationV2 := next.GenerationV2(), true
	if minimumLevel == 0 {
		minimumLevel, generationV2 = next.Generation(), false
	}

	parents := make([]CommitNode, 0, len(next.ParentHashes()))
	for i := range next.ParentHashes() {
		pc, err := next.ParentNode(i)
		if err != nil {
			return nil, err
		}

		parents = append(parents, pc)

		if generationV2 {
			if pc.GenerationV2() < minimumLevel {
				minimumLevel = pc.GenerationV2()
			}
			continue
		}

		if pc.Generation() < minimumLevel {
			minimumLevel = pc.Generation()
		}
	}

	// EXPLORE
	for {
		toExplore, ok := iter.exploreStack.Peek()
		if !ok {
			break
		}

		if toExplore.ID() != next.ID() && iter.exploreStack.Size() == 1 {
			break
		}
		if generationV2 {
			if toExplore.GenerationV2() < minimumLevel {
				break
			}
		} else {
			if toExplore.Generation() < minimumLevel {
				break
			}
		}

		iter.exploreStack.Pop()
		for i, h := range toExplore.ParentHashes() {
			if _, has := iter.ignore[h]; has {
				continue
			}
			iter.inCounts[h]++

			if iter.inCounts[h] == 1 {
				pc, err := toExplore.ParentNode(i)
				if err != nil {
					return nil, err
				}
				iter.exploreStack.Push(pc)
			}
		}
	}

	// VISIT
	for i, h := range next.ParentHashes() {
		if _, has := iter.ignore[h]; has {
			continue
		}
		iter.inCounts[h]--

		if iter.inCounts[h] == 0 {
			iter.visitStack.Push(parents[i])
		}
	}
	delete(iter.inCounts, next.ID())

	return next, nil
}