This page contains some general tips for programming with MTGL.

Type Tips

1) Use size_type types wherever possible.

Similar to the STL, many of the classes in MTGL (i.e. dynamic_array and compressed_sparse_row_graph) define size_type types to be used for certain functions. For instance, the dynamic_array::size_type is used to represent any count associated with the dynamic_array. By using these types, a user doesn't have to worry about any weirdness of what does or doesn't work on a certain platform. That weirdness can be taken care of by the library designer.

You should also make all types that relate to variables of type size_type be of type size_type as well. For instance, if you use an array to store a bunch of positions in a dynamic_array, you should make the array type size_type.

2) Use 'long' instead of 'int' and 'unsigned long' instead of 'unsigned'.

There are two main reasons for this. First, MTGL is designed to be compiled on many platforms which have different size ints. The XMT has 64-bit ints. Many Unix / Linux systems define ints to be 32 bits but longs to be 64 bits. Using long has a much greater chance of producing similar sized integer types on different systems. Second, MTGL is designed to be able to be compiled in a multi-threaded mode on non-XMT machines using qthreads. The qthreads library requires variables used in full-empty operations to be machine-word-size entities. In most cases, long is the machine word size, so preferring long over int reduces headache getting your code to work when using qthreads.

General Tips

1) Use C++ streams for printing to screen.

Yes, I know. Sometimes using cout is a huge pain compared to printf(), especially when you need exact width / precision formatting. However, there is a huge benefit to using C++ streams; it just works regardless of the type. The types for different graphs can be defined differently. For instance, compressed_sparse_row_graph defines size_type as unsigned int while stinger_graph_adapter defines size_type as int64_t. Using printf(), your code will generate warnings for one graph or the other when printing ids, degrees, etc.