ScratchData LogoScratchData
Back to ChromeCat_test's profile

Graph Data Structure Library

CHChromeCat_test•Created May 6, 2022
Graph Data Structure Library
4
3
65 views
View on Scratch

Instructions

This project contains a collection of functions which allow you to create and operate on graph data structures in scratch. This should be used like a library to help in your future graph based projects. (note graph refers to the abstract data structure not the mathematical diagram) For documentation see the notes section. Inside is a small demo populating two graphs, remove this if you are copying it to your own project.

Description

The functions are all named as if there is an instance g of the graphs class and each function is a method of that class. ------------------------------ Documentation ------------------------------ g.__init__(): Called at the start of the project to initialise the graphs class instance. g.alloc(max_degree, length): Allocate memory in the graphs_data list for a graph of size length * max_degree g.add_edge(*G, *u, w, *v): Adds an edge between node *u and node *v g.remove_edge(*u, *u_e): Removes the edge *u_e g.remove_edge(*u, *u_e, *v, *v_e): Removes the edge *u_e. Use this version if you have all 4 pointers. g.get_ptr_to_edge_pointing_at_node(*u, *v): gets the pointer of the edge in node *u, which is pointing at node *v g.get_ptr_to_edge_by_index(*u, idx): returns a pointer to the edge of *u at index idx. (idx starts at 1) g.get_ptr_to_node_by_index(*G, idx): returns a pointer to the node in graph *G at index idx. (idx starts at 1) g.get_ptr_to_next_edge(*u, *e): gets a pointer to the edge after edge *e in the node *u g.get_ptr_to_next_node(*G, *u):gets a pointer to the node after node *u in the graph *G g.get_edge_weight (*e): gets the weight of the edge pointed to by *e g.get_node_value(*u): gets the value of the node pointed at by *u g.add_node(*u, value): sets the value of the node pointed at by *u g.get_metadata(*G): Returns the graphs metadata (max_degree and number of vertices) ------------------------------ Structure of g._graphs_data ------------------------------ 1: # Graph {idx} 2a: {max degree} 2b. {max graph size 2b: {number of vertices in graph} 3a. {node value} 3b. {number of edges in node} 4a: {edge weight} 4b: {ptr to node}

Project Details

Project ID686510887
CreatedMay 6, 2022
Last ModifiedMay 31, 2022
SharedMay 7, 2022
Visibilityvisible
CommentsAllowed