Changes between Version 4 and Version 5 of FirstMtglExample
- Timestamp:
- 11/07/08 15:30:51 (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
FirstMtglExample
v4 v5 17 17 Here is C code source:/trunk/mtgl/static_graph.h that defines and initializes this data structure: 18 18 19 {{{ 19 20 #ifndef STATIC_GRAPH_H 20 21 #define STATIC_GRAPH_H … … 29 30 int* srcs, int* dests, int undirected); 30 31 #endif 31 [jberry@sancha test]$ 32 }}} 33 You will find this file in the mtgl/mtgl subdirectory. The implementation of this simple candidate graph data structure is found in source:/trunk/test/static_graph.c. Here is a simple test program source:/trunk/test/test_static_graph.c that builds a directed graph (a directed triangle), then prints its adjacency structure. 32 34 33 You will find this file in the mtgl/test subdirectory, along with [[media:static_graph.c]], which contains the init_graph function. Here is a simple test program ([[media:test_static_graph.c]]) that builds a directed graph (a directed triangle), then prints its adjacency structure. 34 35 [jberry@sancha test]$ more test_static_graph.c 35 {{{ 36 36 #include "static_graph.h" 37 37 void print(static_graph *g) … … 57 57 return 0; 58 58 } 59 [jberry@sancha test]$ gcc static_graph.c test_static_graph.c 60 [jberry@sancha test]$ ./a.out 61 0: 1 62 1: 2 63 2: 0 64 [jberry@sancha test]$ 59 }}} 60 To build and run: 61 {{{ 62 gcc static_graph.c test_static_graph.c 63 ./a.out 64 0: 1 65 1: 2 66 2: 0 67 }}} 65 68 66 69 Now we have a complete, albeit small, example of a C code that implements a graph algorithm. In order to "MTGL-ize" this code, we need to avoid any explicit use of the underlying data structure. For example, the "print" function above uses the "index" and "end_points" fields of "static_graph," and therefore can be used only with this data structure. To make that function generic, we instantiate an adapter object and use its API to access the graph. The following program uses MTGL primitives to print the graph. We'll consider it ([[media:test_static_graph1.cpp]]) first in its entirety, then dissect it.