Home > matgraph > graph_init.m

graph_init

PURPOSE ^

graph_init(capacity) --- used to initialize the GRAPH_MAGIC data

SYNOPSIS ^

function graph_init(capacity)

DESCRIPTION ^

 graph_init(capacity) --- used to initialize the GRAPH_MAGIC data
 structure. 
 capacity gives the number of "slots" available for graphs.
 If capacity is omitted, a default capacity is used. See the
 code.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001  function graph_init(capacity)
0002 % graph_init(capacity) --- used to initialize the GRAPH_MAGIC data
0003 % structure.
0004 % capacity gives the number of "slots" available for graphs.
0005 % If capacity is omitted, a default capacity is used. See the
0006 % code.
0007 
0008 DEFAULT_CAPACITY = 500;
0009 
0010 
0011 if graph_system_exists
0012     disp('Graph system already initialized');
0013     disp('To start over, use graph_destroy');
0014     return;
0015 end
0016 
0017 global GRAPH_MAGIC;
0018 
0019 % Fields in GRAPH_MAGIC:
0020 %   ngraphs  number of graphs we can hold in this system
0021 %   graphs   cell array to hold the graphs
0022 %   in_use   flags to show which slots are available
0023 %   large_size   threshold for sparse graphs
0024 %   Q  a deque with subfields
0025 %   Q.array   holds the queue values
0026 %   Q.first   index of first element (or 0 if none)
0027 %   Q.last    index of last element (or 0 if none)
0028 
0029 
0030 if (nargin==0)
0031     capacity = DEFAULT_CAPACITY;
0032 end
0033 
0034 
0035 if (capacity < 1)
0036     capacity = DEFAULT_CAPACITY;
0037 end
0038 
0039 GRAPH_MAGIC.ngraphs = capacity;
0040 
0041 GRAPH_MAGIC.graphs = cell(capacity,1);  % hold the graphs
0042 GRAPH_MAGIC.in_use = zeros(capacity,1); % flag to show if slot is free
0043 
0044 GRAPH_MAGIC.Q.array = [];
0045 GRAPH_MAGIC.Q.first = 0;
0046 GRAPH_MAGIC.Q.last = 0;
0047 
0048 
0049 disp(['Graph system initialized. Number of slots = ', ...
0050     int2str(capacity),'.']);
0051 
0052 set_large(1000);

Generated on Thu 13-Mar-2008 14:23:52 by m2html © 2003