A (very) simple graph package that utilizes the Generics features in Go 1.18

Graph

🚧 Work-In-Progress

A (very) simple graph package that utilizes the Generics features in Go 1.18


Usage

package main

import (
  "fmt"

  graph "github.com/willfantom/go-graph"
)

type MyStruct struct {
  Data string
}

func (ms MyStruct) Print() {
  fmt.Println(ms.Data)
}

func main() {
  myGraph := graph.New[MyStruct](true)

  nodeIDA := myGraph.AddNode(MyStruct{
    Data: "Hello, I am Node A",
  })
  nodeIDB := myGraph.AddNode(MyStruct{
    Data: "Hello, I am Node B",
  })
  myGraph.AddEdge(nodeIDA, nodeIDB)

  if bfsResults, err := myGraph.BFS(nodeIDA); err != nil {
    panic(err)
  } else {
    for _, node := range bfsResults {
			node.Print()
		}
	}
}

🎉 No need to cast an interface{} to the desired node type anymore!


Generics

Typically, a graph package will ensure that graph nodes have some form of open type in their structs, for example:

type Node struct {
  Value interface{}
}

However, this requires some type casting during runtime to get back the more specific struct type you want as nodes... (this can easily cause errors)... Using the generics features added in Go 1.18, this package can catch those errors at build time, and thus it has a node structure like:

type Node[T any] struct {
  Value T
  
  ...
}
Owner
Will Fantom
PhD Student @ Lancaster University Unikernels | NFV | Self-Hosting
Will Fantom
Similar Resources

Go package for decoding and encoding TARGA image format

tga tga is a Go package for decoding and encoding TARGA image format. It supports RLE and raw TARGA images with 8/15/16/24/32 bits per pixel, monochro

Sep 26, 2022

Go package for computer vision using OpenCV 4 and beyond.

Go package for computer vision using OpenCV 4 and beyond.

GoCV The GoCV package provides Go language bindings for the OpenCV 4 computer vision library. The GoCV package supports the latest releases of Go and

Jan 1, 2023

Go Perceptual image hashing package

goimagehash Inspired by imagehash A image hashing library written in Go. ImageHash supports: Average hashing Difference hashing Perception hashing Wav

Jan 3, 2023

generativeart is a Go package to generate many kinds of generative art.

generativeart is a Go package to generate many kinds of generative art.

generativeart is a Go package to generate many kinds of generative art. The goal is to collect some excellent generative art (implemented in R or Processing), and rewrite them in Go again

Dec 29, 2022

golang package to find the K most dominant/prominent colors in an image

golang package to find the K most dominant/prominent colors in an image

prominentcolor Find the K most dominant colors in an image The Kmeans function returns the K most dominant colors in the image, ordered in the order o

Nov 7, 2022

Go package captcha implements generation and verification of image and audio CAPTCHAs.

Go package captcha implements generation and verification of image and audio CAPTCHAs.

Package captcha ⚠️ Warning: this captcha can be broken by advanced OCR captcha breaking algorithms. import "github.com/dchest/captcha" Package captch

Dec 30, 2022

openGL Have Fun - A Go package that makes life with OpenGL enjoyable.

glhf openGL Have Fun - A Go package that makes life with OpenGL enjoyable. go get github.com/faiface/glhf Main features Garbage collected OpenGL obje

Jan 1, 2023

Procedural texture generation package.

Procedural texture generation package.

Texture Generation A package for the procedural generation of textures. Based on the ideas contained in the Bryce 3D deep texture editor. More example

Sep 8, 2022

Package shapes provides an algebra for handling shapes

About Package shapes provides the algebra and machinery for dealing with the metainformation of shapes of a tensor. Why a shape package? The shape pac

Jan 14, 2022
Canvas is a Go drawing library based on OpenGL or using software rendering that is very similar to the HTML5 canvas API
Canvas is a Go drawing library based on OpenGL or using software rendering that is very similar to the HTML5 canvas API

Go canvas Canvas is a pure Go library that provides drawing functionality as similar as possible to the HTML5 canvas API. It has nothing to do with HT

Jan 3, 2023
Generate image plots of processes' memory usage very quickly, within a single binary.
Generate image plots of processes' memory usage very quickly, within a single binary.

memplot A small utility written in golang to quickly plot memory usage of processes. memplot constantly samples memory usage of a process, for a given

Apr 17, 2021
Draw graphs through GO MOD GRAPH output
Draw graphs through GO MOD GRAPH output

go-mod-graph-chart build chart by go mod graph output Install $ go get -u github.com/PaulXu-cn/go-mod-graph-chart/gmchart Usage

Dec 14, 2022
Easily customizable Social image (or Open graph image) generator

fancycard Easily customizable Social image (or Open graph image) generator Built with Go, Gin, GoQuery and Chromedp Build & Run Simply, Clone this rep

Jan 14, 2022
Imaging is a simple image processing package for Go
Imaging is a simple image processing package for Go

Imaging Package imaging provides basic image processing functions (resize, rotate, crop, brightness/contrast adjustments, etc.). All the image process

Dec 30, 2022
p5 is a simple package that provides primitives resembling the ones exposed by p5js.org
p5 is a simple package that provides primitives resembling the ones exposed by p5js.org

p5 p5 is a simple package that provides primitives resembling the ones exposed by the p5/processing library. License p5 is released under the BSD-3 li

Dec 11, 2022
magicimage is a simple image validation & save with rich feature package for net/http

Installation go get github.com/IndominusByte/magicimage Usage examples A few usage examples can be found below. See the documentation for the full lis

Feb 5, 2022
A pure Go package for coordinate transformations.

WGS84 A pure Go package for coordinate transformations. go get github.com/wroge/wgs84 Usage east, north, h := wgs84.LonLat().To(wgs84.ETRS89UTM(32)).R

Nov 25, 2022
Go package for fast high-level image processing powered by libvips C library

bimg Small Go package for fast high-level image processing using libvips via C bindings, providing a simple programmatic API. bimg was designed to be

Jan 2, 2023
Go bindings for GStreamer (retired: currently I don't use/develop this package)

Retired. I don't use/develop this package anymore. Go bindings for GStreamer at a very early stage of maturity. This package is based on GLib bindings

Nov 10, 2022