Changes between Version 4 and Version 5 of FirstMtglExample


Ignore:
Timestamp:
11/07/08 15:30:51 (10 years ago)
Author:
jberry
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FirstMtglExample

    v4 v5  
    1717Here is C code source:/trunk/mtgl/static_graph.h that defines and initializes this data structure: 
    1818 
     19{{{ 
    1920 #ifndef STATIC_GRAPH_H 
    2021 #define STATIC_GRAPH_H 
     
    2930                int* srcs, int* dests, int undirected); 
    3031 #endif 
    31  [jberry@sancha test]$  
     32 }}} 
     33You 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. 
    3234 
    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{{{ 
    3636 #include "static_graph.h" 
    3737 void print(static_graph *g) 
     
    5757        return 0; 
    5858 } 
    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}}} 
     60To 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}}} 
    6568 
    6669Now 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.