// Copyright (c) 2010, 2020 Kiel University and others.
// Copyright (c) 2026 The elk-go Authors.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0.
//
// SPDX-License-Identifier: EPL-2.0

package p2layers

import 

// LongestPathLayerer assigns each node according to its longest path to a
// sink. Layers are prepended exactly as in ELK 0.8.1.
type LongestPathLayerer struct{}

func (*LongestPathLayerer) (
	 *layered.LGraphArena,
	 layered.LGraphID,
) layered.ProcessorConfiguration {
	return layered.NetworkSimplexLayeringConfiguration()
}

func (*LongestPathLayerer) ( *layered.LGraphArena,  layered.LGraphID) error {
	 := .Graph()
	 := .LayerlessNodes
	 := make([]int, len())
	for ,  := range  {
		.Node().ID = 
		[] = -1
	}

	var  func(layered.LNodeID) int
	 = func( layered.LNodeID) int {
		 := .Node().ID
		if [] >= 0 {
			return []
		}
		 := 1
		for ,  := range .NodeOutgoingEdges() {
			 := .EdgeTargetNode()
			if  ==  {
				continue
			}
			 := () + 1
			if  >  {
				 = 
			}
		}
		for len(.Layers) <  {
			 := .AddLayer()
			.Layers = append(.Layers, 0)
			copy(.Layers[1:], .Layers[:len(.Layers)-1])
			.Layers[0] = 
		}
		 := .Layers[len(.Layers)-]
		.SetNodeLayer(, &)
		[] = 
		return 
	}

	for ,  := range  {
		()
	}
	.LayerlessNodes = .LayerlessNodes[:0]
	return nil
}