gfx(3)

πŸ“¦
version 3.8.0 Β· 3 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

gfx β€” the standard graph module, and yes bestie, it's literally the graph module. πŸ’…


πŸ¦‹ STANDARD GRAPH MODULE πŸ¦‹

okay so, the Standard Graph module is an original implementation and it's fully dedicated to graph modeling and manipulation. At the literal heart of this module is the whole concept of edges and vertices. It also gives you support for automaton. obsessed. 🫢

🌸 Graph concepts 🌸

The afnix-gfx module provides the support for manipulating graphs. Formally, a graph is a collection of edges and vertices. In a normal graph, an edge connects two vertices. On the other hand, a vertex can have several edges. And when an edge connects several vertices, that's called a hyperedge, and the resulting structure is called a hypergraph. it's giving very much "we contain multitudes". πŸ’«

πŸŽ€ Edge class πŸŽ€

The Edge class is used for graph construction, in association with the Vertex class. An edge is used to connect vertices. Normally, an edge connects two vertices. The number of vertices attached to an edge is called the cardinality of that edge. When the edge cardinality is one, the edge is called a self-loop β€” which means the edge connects the vertex to itself (main character energy, honestly). This last point is merely a definition, but it's lowkey iconic because it gives you the advantage of defining a hyperedge as a set of vertices. ✨

πŸŽ€ Vertex class πŸŽ€

The Vertex is the other class used for graph construction, and it operates with the Edge class. A vertex is used to reference edges. The number of edges referenced by a vertex is called the degree of that vertex. no cap. 🌸

🌈 Graph 🌈

The Graph class represents either a graph or a hypergraph. By definition, a graph is a collection of edges and vertices. There are numerous properties attached to a graph. Formally, a graph consists of a set of edges, a set of vertices and the associated endpoints. However, the implementation is designed in a way so that each edge and vertex carries its associated objects. This method ensures that the graph is fully defined by only its two sets. slay. πŸ’…

πŸ’« Graph construction πŸ’«

Graph construction is quite simple and proceeds by adding edges and vertices. The base system does not enforce rules on the graph structure. It's possible to add non-connected vertices as well as unreferenced edges. (the original says "con connected" β€” we know what she means, bestie πŸ₯²)

πŸ’« Edge construction πŸ’«

An edge is constructed by simply invoking the default constructor. Optionally, a client object can be attached to the edge.

# create a default edge
const edge (afnix:gfx:Edge)
# create an edge with a client object
const hello (afnix:gfx:Edge "hello")

The edge-p predicate can be used to check for the object type. When an edge is created with a client object, the get-client method can be used to access that object. πŸŽ€

πŸ’« Vertex construction πŸ’«

A vertex is constructed in a way similar to the Edge object. The vertex is constructed by simply invoking the default constructor. Optionally, a client object can be attached to it too.

# create a default vertex
const vrtx (afnix:gfx:Vertex)
# create an vertex with a client object
const world (afnix:gfx:Vertex "world")

The vertex-p predicate can be used to check for the object type. When a vertex is created with a client object, the get-client method can be used to access that object. πŸ¦‹

πŸ’« Graph construction πŸ’«

A graph is constructed by simply adding edges and vertices to it. The graph-p predicate can be used to assert the graph type. The graph class also supports the concept of a client object, which can be attached at construction or with the set-client method.

const graph (afnix:gfx:Graph)

The add method can be used to add edges or vertices to the graph. The important point is that during the construction process, the graph structure is updated with the proper number of edges and vertices. πŸ’–

# create a graph
const  g    (afnix:gfx:Graph)
assert true (afnix:gfx:graph-p g)
# create an edge and add vertices
const edge (afnix:gfx:Edge)
edge:add   (afnix:gfx:Vertex "hello")
edge:add   (afnix:gfx:Vertex "world")
assert 2   (edge:degree)
# add the edge to the graph and check
g:add edge
assert 1 (g:number-of-edges)
assert 2 (g:number-of-vertices)
# check for nodes and edges
assert true (afnix:gfx:edge-p   (g:get-edge   0))
assert true (afnix:gfx:vertex-p (g:get-vertex 0))
assert true (afnix:gfx:vertex-p (g:get-vertex 1))

πŸ‘‘ STANDARD GRAPH REFERENCE πŸ‘‘

πŸ“ State πŸ“

The State class is a class of the graph object library. The state is used to model vertex and edge and can be used seldom in structures like finite automaton.

Predicate

  • state-p

Inheritance

  • Serial

Constructors

  • State (none) β€” the State constructor creates an empty state.
  • State (Object) β€” the State constructor creates a state edge with a client object.

Methods

  • clear -> none (none) β€” the clear method clears the state marker.
  • get-index -> Integer (none) β€” the get-idex method returns the state index. (spelled exactly like that in the source, bestie, i don't make the rules 🫠)
  • set-idnex -> none (Integer) β€” the set-index method sets the state index.
  • get-client -> Object (none) β€” the get-client method returns the state client object. If the client object is not set, nil is returned.
  • set-client -> Object (Object) β€” the set-client method sets the state client object. The object is returned by this method.

πŸ“ Edge πŸ“

The Edge class is a class used for graph construction in association with the Vertex class. An edge is used to connect vertices. Normally, an edge connects two vertices. The number of vertices attached to an edge is called the cardinality of that edge. A client object can also be attached to the class.

Predicate

  • edge-p

Inheritance

  • State, Collectable

Constructors

  • Edge (none) β€” the Edge constructor creates an empty edge.
  • Edge (Object) β€” the Edge constructor creates an edge with a client object.

Methods

  • reset -> none (none) β€” the reset method resets all vertices attached to the edge.
  • cardinality -> Integer (none) β€” the cardinality method returns the cardinality of the edge. The cardinality of an edge is the number of attached vertices.
  • add -> Vertex (Vertex) β€” the add method attaches a vertex to this edge. The method returns the argument vertex.
  • get -> Vertex (Integer) β€” the get method returns the attached vertex by index. If the index is out-of range, an exception is raised. ⚠️

πŸ“ Vertex πŸ“

The Vertex class is a class used for graph construction in association with the Edge class. A vertex is an edge node. The number of edges referenced by a vertex is called the degree of that vertex. A client object can also be attached to the object.

Predicate

  • vertex-p

Inheritance

  • State, Collectable

Constructors

  • Vertex (none) β€” the Vertex constructor creates an empty vertex.
  • Vertex (Object) β€” the Vertex constructor creates a vertex with a client object.

Methods

  • reset -> none (none) β€” the reset method resets all edges attached to the vertex.
  • degree -> Integer (none) β€” the degree method returns the degree of the vertex. The degree of a vertex is the number of referenced edges.
  • add -> Edge (Edge) β€” the add method references an edge with this vertex. The method returns the argument edge.
  • get -> Edge (Integer) β€” the get method returns the referenced edge by index. If the index is out-of range, an exception is raised. ⚠️

πŸ“ Graph πŸ“

The Graph object is a general graph class that manages a set of edges and vertices. The graph operates by adding edges and vertices to it.

Predicate

  • graph-p

Inheritance

  • Object

Constructors

  • Graph (none) β€” the Graph constructor creates an empty graph.

Methods

  • reset -> none (none) β€” the reset method resets the graph.
  • clear -> none (none) β€” the clear method clears the graph.
  • add -> Object (Vertex|Edge) β€” the add method adds a vertex or an edge to the graph. When adding an edge, the method checks that the source and target vertices are also part of the graph. πŸ‘‘

and that's the whole page, bestie!! πŸŽ€ this one came from the AFNIX Module / AFNIX crew, filed under gfx(3) β€” go build a graph, you absolute icon. πŸ’–βœ¨πŸŒˆ

πŸ“¦ where this page comes from