Glauber Dynamics in C
Simulation for Glauber Dynamics written in C11
Data Structures | Typedefs | Functions
vertex.h File Reference

Define the vertex struct and functions relating to it. More...

#include "edge.h"

Go to the source code of this file.

Data Structures

struct  vertex
 The vertex struct containing the neighbouring edges as pointers. More...
 

Typedefs

typedef struct vertex vertex
 The typedef of the vertex struct.
 

Functions

vertexvertex_new ()
 Allocate the memory for a new vertex with no neighbours. More...
 
void vertex_free (vertex *v)
 Free the input vertex pointer and all edges pointing to it. More...
 
void vertex_add_edge_to_neighbourhood (vertex *v, edge *e)
 Add the edge e to the neighbourhood v->edges. More...
 
void vertex_rm_edge_from_neighbourhood (vertex *v, edge *e)
 Remove edge e from neighbourhood of vertex v. More...
 
edgevertex_find_connecting_edge (vertex *v, int dst)
 Find the edge that connects vertex v with the vertex of index dst. More...
 

Detailed Description

Define the vertex struct and functions relating to it.

The vertex struct is defined with its general memory management functions and edge adding and removing utitilities are defined.

Function Documentation

◆ vertex_add_edge_to_neighbourhood()

void vertex_add_edge_to_neighbourhood ( vertex v,
edge e 
)

Add the edge e to the neighbourhood v->edges.

This also increments vertex::dim and vertex::local_weight accordingly.

Parameters
vPointer to the vertex whose neighbourhood should be extended.
ePointer to the edge to add to the neighbourhood of v.

◆ vertex_find_connecting_edge()

edge * vertex_find_connecting_edge ( vertex v,
int  dst 
)

Find the edge that connects vertex v with the vertex of index dst.

Parameters
vThe vertex whose neighbourhood is to be searched.
dstThe target vertex of the desired edge.
Returns
NULL if no edge is found or a pointer to the connecting edge.

◆ vertex_free()

void vertex_free ( vertex v)

Free the input vertex pointer and all edges pointing to it.

The edges are freed in this function since they would otherwise be invalid. Invoke this function only after removing the edge from all other neighbourhoods so that those will not contain an invalid neighbour (cf. graph_rm_edge).

Parameters
vThe vertex to be freed.
Todo:
Add graph_rm_vertex to weightedgraph.h which automatically takes care of removing edges from all neighbours and then frees the vertex.

◆ vertex_new()

vertex * vertex_new ( )

Allocate the memory for a new vertex with no neighbours.

Returns
The pointer to the newly allocated vertex.

◆ vertex_rm_edge_from_neighbourhood()

void vertex_rm_edge_from_neighbourhood ( vertex v,
edge e 
)

Remove edge e from neighbourhood of vertex v.

The function checks if e is contained in the neighbourhood of v and does nothing if that is not the case. This also decrements vertex::dim and vertex::local_weight accordingly.

Parameters
vPointer to the vertex whose nieghbourhood should be shrunk.
ePointer to the edge to remove fromthe neighbourhood of v.