Verse Library verse

01 Snippet

Implements weighted graph data structures with vertices, edges, and adjacency lists for network or pathfinding logic.

extracted-snippets/community/snippets/2WVO/fortnite-graphs/01-snippet.verse

# Source URL: https://dev.epicgames.com/community/snippets/2WVO/fortnite-graphs
# Local doc:  epic-docs/community/snippets/2WVO/fortnite-graphs.md
  # Module library for mathematical graphs in Verse
  Graphs<public> := module:
  using { /Verse.org/Random }
  # Integer weighted graph
  IntegerWeightedGraph<public> := class<concrete>:
  Vertices:?[]int = false
  Edges:?[]tuple(int,int,int) = false
  AdjacencyList:?[int][]tuple(int,int) = false
  GetEdges<public>()<decides><transacts>:[]tuple(int,int,int) =
  Edges?
  GetVertices<public>()<decides><transacts>:[]int =
  Vertices?
  GetAdjacencyList<public>()<decides><transacts>:[int][]tuple(int,int) =
  AdjacencyList?
  DebugString<public>()<transacts>:string =
  var ReturnString: string = ""
  if (List:=AdjacencyList?):
  for (Vertex->VertexEdges:List):
  for(Edge:VertexEdges):
  set ReturnString += "\t{Vertex} - ({Edge(1)}) -> {Edge(0)}\n"
  ReturnString
  # Float weighted graph
  FloatWeightedGraph<public> := class<concrete>:
  Vertices:?[]int = false
  Edges:?[]tuple(int,int,float) = false
  AdjacencyList:?[int][]tuple(int,float) = false
  GetEdges<public>()<decides><transacts>: []tuple(int,int,float) =
  Edges?

Sign in free to read the full source 🌴

This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.

Sign in with Discord

Comments

    Sign in to vote, comment, or suggest an edit. Sign in