graph

package
v0.0.0-...-ccf6f70 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2014 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

*

  • Package graph implements a Graph that can be either a King's graph
  • or a Grid graph. It can generate a graph from a given image.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Edge

type Edge struct {
	// contains filtered or unexported fields
}

*

  • Represents a graph edge. It contains the ids of the two vertices
  • that it connects and the weight of the edge between them

func (*Edge) U

func (e *Edge) U() int

*

  • Return the id of one of the vertices that Edge e connects

func (*Edge) V

func (e *Edge) V() int

*

  • Return the id of one of the vertices that Edge e connects

func (*Edge) Weight

func (e *Edge) Weight() float64

*

  • Return the weight of Edge e

type EdgeList

type EdgeList []Edge

*

  • Used to store all the edges that the graph contains.
  • It can be used with sort.Sort

func (EdgeList) Len

func (edges EdgeList) Len() int

*

  • Return the number of edges that the EdgeList edges stores

func (EdgeList) Less

func (edges EdgeList) Less(i, j int) bool

*

  • Returns true if the weight of the edge i is less than the weight
  • of the edge j

func (EdgeList) Swap

func (edges EdgeList) Swap(i, j int)

*

  • In place swap of two edges i and j in the edge list

type Graph

type Graph struct {
	// contains filtered or unexported fields
}

*

  • Graph datatype. Contains a list of edges, the graph width and height and
  • if it's a King's graph or a Grid graph

func FromImage

func FromImage(img image.Image, weight WeightFn, graphType GraphType) *Graph

*

  • Returns a new graph that represents the image img. The graph will be either
  • a King's grph or a Grid graph. It will compute the edge weights using the
  • provided function weight.

func New

func New(width, height int, graphType GraphType) *Graph

*

  • Returns a new width x height King's or Grid graph. It assigns a weight of Infinity
  • to all edges

func (*Graph) Edges

func (g *Graph) Edges() EdgeList

*

  • Returns all the edges that the graph has

func (*Graph) Height

func (g *Graph) Height() int

*

  • Returns the height of a graph

func (*Graph) Neighbors

func (g *Graph) Neighbors(v int) <-chan int

*

  • Return the ids of the vertices to which v is adjacent

func (*Graph) TotalEdges

func (g *Graph) TotalEdges() int

*

  • Returns the total number of edges that the graph has

func (*Graph) TotalVertices

func (g *Graph) TotalVertices() int

*

  • Returns the total number of vertices that the graph has

func (*Graph) Weight

func (g *Graph) Weight(u, v int) float64

func (*Graph) Width

func (g *Graph) Width() int

*

  • Returns the width of a graph

type GraphType

type GraphType int

*

  • Used to recongise which type of graph to generate
const (
	GRIDGRAPH  GraphType = iota
	KINGSGRAPH GraphType = iota
)

type Pixel

type Pixel struct {
	X, Y  int
	Color color.Color
}

*

  • Used to compute the weight of an edge when generating a graph
  • from an image

type WeightFn

type WeightFn func(Pixel, Pixel) float64

*

  • Type of the functions that are used to compute the weight of
  • an edge when generating a graph from an image

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL