func (m *Mesh) LastNode() *MeshNode {
	l := m.Start.likelyPath()
	return l[len(l)-1]
}
LastNode - returns the last node in a mesh
The last node is the last element of the likeliest path
package mesh
import (
	"crypto/sha256"
	"fmt"
	"log"
	"os"
	"strconv"
	"github.com/9elements/autorev/tracelog"
	"github.com/emicklei/dot"
	lcs "github.com/yudai/golcs"
)
type MeshNode struct {
	Id uint64
	Propability     uint64
	Next, Prev      []*MeshNode
	Hash            string
	TLE             tracelog.TraceLogEntry
	FirmwareOptions []map[string]uint64
	IsNoop bool
}
type Mesh struct {
	Start MeshNode
	Pathes uint64
	Nodes  []*MeshNode
	ID uint64
}
type Branch Mesh
func lcsMeshNodes(left []*MeshNode, right []*MeshNode) []interface{} {
	var leftIface []interface{} = make([]interface{}, len(left))
	var rightIface []interface{} = make([]interface{}, len(right))
	for i, d := range left {
		leftIface[i] = d.Hash
	}
	for i, d := range right {
		rightIface[i] = d.Hash
	}
	return lcs.New(leftIface, rightIface).Values()
}
func (mn *MeshNode) comparePrev(other *MeshNode) bool {
	if len(mn.Prev) != len(other.Prev) {
		return false
	}
	for _, v1 := range mn.Prev {
		found := false
		for _, v2 := range other.Prev {
			if v1.Id == v2.Id {
				found = true
				break
			}
		}
		if !found {
			return false
		}
	}
	return true
}
func (mn *MeshNode) likelyPath() []*MeshNode {
	i := mn
	var list []*MeshNode
	for true {
		if len(i.Next) == 0 {
			break
		}
		var p uint64
		var l *MeshNode
		for j := range i.Next {
			if i.Next[j].Propability >= p {
				p = i.Next[j].Propability
				l = i.Next[j]
			}
		}
		i = l
		list = append(list, i)
	}
	return list
}
func (mn *MeshNode) FirstPath() []*MeshNode {
	i := mn
	var list []*MeshNode
	for true {
		if len(i.Next) == 0 {
			break
		}
		i = i.Next[0]
		list = append(list, i)
	}
	return list
}
func (mn *MeshNode) LenFirstPath() uint {
	i := mn
	length := uint(0)
	for true {
		if len(i.Next) == 0 {
			break
		}
		i = i.Next[0]
		length++
	}
	return length
}
func (mn *MeshNode) NextPath(lastPath []*MeshNode) []*MeshNode {
	var last *MeshNode
	var list []*MeshNode
	if len(lastPath) <= 1 {
		return nil
	}
	lastPath = append([]*MeshNode{mn}, lastPath...)
	last = lastPath[len(lastPath)-1]
	lastPath = lastPath[:len(lastPath)-1]
	for len(lastPath) > 0 {
		n := lastPath[len(lastPath)-1]
		if len(n.Next) > 1 {
			found := -1
			for idx := range n.Next {
				if n.Next[idx].Hash == last.Hash {
					found = idx
					break
				}
			}
			if found == -1 {
				return nil
			}
			if found+1 != len(n.Next) {
				list = append(lastPath, n.Next[found+1])
				break
			}
		}
		last = lastPath[len(lastPath)-1]
		lastPath = lastPath[:len(lastPath)-1]
	}
	if list == nil {
		return list
	}
	list = list[1:]
	n := list[len(list)-1]
	for len(n.Next) > 0 {
		list = append(list, n.Next[0])
		n = n.Next[0]
	}
	return list
}
func (mn *MeshNode) AnyPathesContainNode(find *MeshNode) bool {
	for p := mn.FirstPath(); p != nil; p = mn.NextPath(p) {
		for _, i := range p {
			if i.Id == find.Id {
				return true
			}
		}
	}
	return false
}
func (mn *MeshNode) CommonMergePoint() *MeshNode {
	var n *MeshNode
	for i, first := range mn.Next {
		for j := i; j < len(mn.Next); j++ {
			second := mn.Next[j]
			for left := first.FirstPath(); left != nil; left = first.NextPath(left) {
				for right := second.FirstPath(); right != nil; right = first.NextPath(right) {
					for i := 0; i < len(left); i++ {
						found := false
						for j := 0; j < len(right); j++ {
							if left[i].Id == right[j].Id {
								if n != nil {
									if n.AnyPathesContainNode(left[i]) {
										n = left[i]
									}
								} else {
									n = left[i]
								}
								found = true
								break
							}
						}
						if found {
							break
						}
					}
				}
			}
		}
	}
	return n
}