Functions

src/misc.c File Reference

A collection of useful comparators and print functions. More...

#include <assert.h>
#include <stdio.h>
#include <time.h>
#include <sys/resource.h>
#include "misc.h"
#include "LinkedList.h"
#include "MemoryManager.h"

Functions

int nodeComparator (void *node1, void *node2)
 compare integers return -1,0,1 for <,=,>
int sortComparator (void *node1, void *node2)
 compare integer pointers; return -1,0,1 for <,=,>; used for calling sort().
void printArray (int *array, int size)
 print an array of integers to standard out.
void printArrayOfLinkedLists (LinkedList **listOfLists, int size)
 print an abbreviated version of an adjacency list
void printClique (int *clique)
 print a clique, that is formatted as an integer array ending with -1.
void printInt (void *integer)
 print an integer
void destroyCliqueResults (LinkedList *cliques)
 destroy a linked list of integer arrays that have -1 in the last cell, have have been allocated by the user.
LinkedList ** readInGraphAdjList (int *n, int *m)
 read in a graph from stdin and return an adjacency list, as an array of linked lists of integers.
void runAndPrintStatsMatrix (long(*function)(char **, LinkedList *, int), const char *algName, char **adjMatrix, LinkedList *cliques, int n)
 execute an maximal clique listing algorithm that takes an adjacency matrix as input, time it, and print the number of maximal cliques found along with time information.
void runAndPrintStatsListList (long(*function)(LinkedList **, int **, LinkedList *, int *, int), const char *algName, LinkedList **adjListLinked, int **adjListArray, LinkedList *cliques, int *degree, int n)
 execute an maximal clique listing algorithm that takes an adjacency list as input, time it, and print the number of maximal cliques found along with time information.
void processClique (LinkedList *cliques, LinkedList *clique)
 process a clique, which may include printing it in one of several formats and/or adding the clique to a linked list.

Detailed Description

A collection of useful comparators and print functions.

Author:
Darren Strash (first name DOT last name AT gmail DOT com)

Copyright (c) 2011 Darren Strash. This code is released under the GNU Public License (GPL) 3.0.

gplv3-127x51.png
See GPL 3.0 here

Function Documentation

void destroyCliqueResults ( LinkedList cliques  ) 

destroy a linked list of integer arrays that have -1 in the last cell, have have been allocated by the user.

Parameters:
cliques the linked list of integer arrays
int nodeComparator ( void *  node1,
void *  node2 
)

compare integers return -1,0,1 for <,=,>

Parameters:
node1 an integer
node2 an integer
Returns:
-1 if <, 0 if =, and 1 if >.
void printArray ( int *  array,
int  size 
)

print an array of integers to standard out.

Parameters:
array the array to print
size the length of the array
void printArrayOfLinkedLists ( LinkedList **  listOfLists,
int  size 
)

print an abbreviated version of an adjacency list

Parameters:
listOfLists the adjacency list
size the number of vertices in the graph
void printClique ( int *  clique  ) 

print a clique, that is formatted as an integer array ending with -1.

Parameters:
clique the clique.
void printInt ( void *  integer  ) 

print an integer

Parameters:
integer an integer cast to a void*
void processClique ( LinkedList cliques,
LinkedList clique 
) [inline]

process a clique, which may include printing it in one of several formats and/or adding the clique to a linked list.

Parameters:
cliques A linked list of cliques to return. (only available when compiled with RETURN_CLIQUES_ONE_BY_ONE defined)
clique the clique to add to the linked list
LinkedList** readInGraphAdjList ( int *  n,
int *  m 
)

read in a graph from stdin and return an adjacency list, as an array of linked lists of integers.

Parameters:
n this will be the number of vertices in the graph when this function returns.
m this will be 2x the number of edges in the graph when this function returns.
Returns:
an array of linked lists of integers (adjacency list) representation of the graph
void runAndPrintStatsListList ( long(*)(LinkedList **, int **, LinkedList *, int *, int)  function,
const char *  algName,
LinkedList **  adjListLinked,
int **  adjListArray,
LinkedList cliques,
int *  degree,
int  n 
)

execute an maximal clique listing algorithm that takes an adjacency list as input, time it, and print the number of maximal cliques found along with time information.

Parameters:
function a function that computes all maximal cliques and returns the number of maximal cliques found
algName a zero-terminated character string that will be printed with the statistics of the algorithm run.
adjListLinked the input graph in the array of linked lists (adjacency list) format.
adjListArray the input graph in the array of arrays (adjacency list) format.
cliques A linked list of cliques to return. (only available when compiled with RETURN_CLIQUES_ONE_BY_ONE defined)
degree An array, indexed by vertex, containing the degree of that vertex.
n the number of vertices in the input graph
void runAndPrintStatsMatrix ( long(*)(char **, LinkedList *, int)  function,
const char *  algName,
char **  adjMatrix,
LinkedList cliques,
int  n 
)

execute an maximal clique listing algorithm that takes an adjacency matrix as input, time it, and print the number of maximal cliques found along with time information.

Parameters:
function a function that computes all maximal cliques and returns the number of maximal cliques found
algName a zero-terminated character string that will be printed with the statistics of the algorithm run.
adjMatrix the input graph in the adjacency matrix format.
cliques A linked list of cliques to return. (only available when compiled with RETURN_CLIQUES_ONE_BY_ONE defined)
n the number of vertices in the input graph
int sortComparator ( void *  node1,
void *  node2 
)

compare integer pointers; return -1,0,1 for <,=,>; used for calling sort().

Parameters:
node1 a pointer to an integer
node2 a pointer to an integer
Returns:
-1 if <, 0 if =, and 1 if >.
 All Data Structures Files Functions Variables Typedefs Defines