Concorde util.h functions
CCutil_linked_radixsort
File:
UTIL/sortrus.c
Header:
util.h
Prototype:
char *CCutil_linked_radixsort (char *data, char *datanext,
char *dataval, int valsize)
Description:
USAGE:
head = (bar *) CCutil_linked_radixsort ((char *) head,
(char *) &(head->next), (char *) &(head->val), sizeof (int));
Then head is the start of the linked list in increasing order of
val, with next as the field that links the bars.
WARNING: DOES NOT HANDLE NEGATIVE NUMBERS PROPERLY.
CCutil_int_array_quicksort
File:
UTIL/sortrus.c
Header:
util.h
Prototype:
void CCutil_int_array_quicksort (int *len, int n)
Description:
len - the array to be sorted
n - the number of elements in len
Uses quicksort to put len in increasing order.
CCutil_int_perm_quicksort
File:
UTIL/sortrus.c
Header:
util.h
Prototype:
void CCutil_int_perm_quicksort (int *perm, int *len, int n)
Description:
perm - must be allocated and initialized by the calling routine,
it will be arranged in increasing order of len.
n - the number of elements in perm and len.
CCutil_double_perm_quicksort
File:
UTIL/sortrus.c
Header:
util.h
Prototype:
void CCutil_double_perm_quicksort (int *perm, double *len, int n)
Description:
perm - must be allocated and initialized by the calling routine,
it will be arranged in increasing order of len.
n - the number of elements in perm and len.
CCutil_rselect
File:
UTIL/sortrus.c
Header:
util.h
Prototype:
void CCutil_rselect (int *arr, int l, int r, int m,
double *coord, CCrandstate *rstate)
Description:
arr - permutation that will be rearranged
l,r - specify the range of arr that we are interested in
m - is the index into l,r that is the break point for the perm
coord - gives the keys that determine the ordering
CCutil_zeit
File:
UTIL/zeit.c
Header:
util.h
Prototype:
double CCutil_zeit (void)
Description:
- To measure cpu time.
To use this, set double t = CCutil_zeit (), run the function you
want to time, then compute CCutil_zeit () - t.
CCutil_real_zeit
File:
UTIL/zeit.c
Header:
util.h
Prototype:
double CCutil_real_zeit (void)
Description:
- To measure wall clock time.
To use this, set double t = CCutil_real_zeit (), run the function
you want to time, then compute CCutil_real_zeit () - t.
CCutil_init_timer
File:
UTIL/zeit.c
Header:
util.h
Prototype:
void CCutil_init_timer (CCutil_timer *t, const char *name)
Description:
- Initializes a CCutil_timer, and gives it a name.
- The name is silently truncated if it is too long.
CCutil_start_timer
File:
UTIL/zeit.c
Header:
util.h
Prototype:
void CCutil_start_timer (CCutil_timer *t)
Description:
- Starts the timer.
CCutil_suspend_timer
File:
UTIL/zeit.c
Header:
util.h
Prototype:
void CCutil_suspend_timer (CCutil_timer *t)
Description:
- Suspends the timer. Similar to CCutil_stop_timer, but doesn't
count a call, and doesn't output.
CCutil_resume_timer
File:
UTIL/zeit.c
Header:
util.h
Prototype:
void CCutil_resume_timer (CCutil_timer *t)
Description:
- Resumes the timer after a suspend.
CCutil_stop_timer
File:
UTIL/zeit.c
Header:
util.h
Prototype:
double CCutil_stop_timer (CCutil_timer *t, int printit)
Description:
- Stops the timer, and returns the time since the last start.
- if printit == 1, outputs the time spent.
- if printit == 2, outputs the time spent only if nonzero
- if printit == 3,4, like 1,2, except brief, table-form output
CCutil_total_timer
File:
UTIL/zeit.c
Header:
util.h
Prototype:
double CCutil_total_timer (CCutil_timer *t, int printit)
Description:
- Returns the cumulative time for this timer.
- if printit == 1, outputs the cumulative time.
- if printit == 2, outputs the cumulative time only if nonzero
- if printit == 3,4, like 1,2, except brief, table-form output
CCutil_nextprime
File:
UTIL/util.c
Header:
util.h
Prototype:
unsigned int CCutil_nextprime (unsigned int x)
Description:
FINDS the smallest positive prime >= x
CCutil_our_gcd
File:
UTIL/util.c
Header:
util.h
Prototype:
int CCutil_our_gcd (int a, int b)
Description:
COMPUTES gcd(a,b)
-gcd(a,b) is always >= 0
-a and b can be negative, positive, or zero
CCutil_our_lcm
File:
UTIL/util.c
Header:
util.h
Prototype:
int CCutil_our_lcm (int a, int b)
Description:
COMPUTES lcm(a,b)
-lcm(a,b) is always >= 0
-a and b can be negative, positive, or zero
CCutil_strchr
File:
UTIL/util.c
Header:
util.h
Prototype:
char *CCutil_strchr (char *s, int c)
Description:
RETURNS a pointer to the first occurrence of c in s, or NULL if c
does not occur in s
CCutil_strrchr
File:
UTIL/util.c
Header:
util.h
Prototype:
char *CCutil_strrchr (char *s, int c)
Description:
RETURNS a pointer to the last occurrence of c in s, or NULL if c
does not occur in s
CCutil_strchr_c
File:
UTIL/util.c
Header:
util.h
Prototype:
const char *CCutil_strchr_c (const char *s, int c)
Description:
RETURNS a pointer to the first occurrence of c in s, or NULL if c
does not occur in s. A variant for const strings.
CCutil_strrchr_c
File:
UTIL/util.c
Header:
util.h
Prototype:
const char *CCutil_strrchr_c (const char *s, int c)
Description:
RETURNS a pointer to the last occurrence of c in s, or NULL if c
does not occur in s. A variant for const strings.
CCutil_strdup
File:
UTIL/util.c
Header:
util.h
Prototype:
char *CCutil_strdup (const char *s)
Description:
RETURNS a pointer to a copy of s, allocated with CC_SAFE_MALLOC,
or NULL if unable to allocate space for the string
CCutil_strdup2
File:
UTIL/util.c
Header:
util.h
Prototype:
char *CCutil_strdup2 (const char *s)
Description:
RETURNS a pointer to a copy of s up until the first whitespace,
allocated with CC_SAFE_MALLOC, or NULL if unable to allocate space
for the string.
CCutil_readstr
File:
UTIL/util.c
Header:
util.h
Prototype:
void CCutil_readstr (FILE *f, char *s, int len)
Description:
READS a string from f into s. The string is terminated by a
whitespace character (space, tab, newline) or EOF. The entire
string including the terminating character is read, but only at
most len characters are stored in s, including the terminating
NULL.
CCutil_printlabel
File:
UTIL/util.c
Header:
util.h
Prototype:
void CCutil_printlabel (void)
Description:
PRINTS information identifying a machine
CCutil_sprand
File:
UTIL/urandom.c
Header:
util.h
Prototype:
void CCutil_sprand (int seed, CCrandstate *r)
Description:
- Call once to initialize the generator.
CCutil_lprand
File:
UTIL/urandom.c
Header:
util.h
Prototype:
int CCutil_lprand (CCrandstate *r)
Description:
- Returns an integer in the range 0 to CC_PRANDMAX - 1.
CCutil_normrand
File:
UTIL/urandom.c
Header:
util.h
Prototype:
double CCutil_normrand (CCrandstate *r)
Description:
- Returns a normally-distributed random value with mean 0 and
deviation 1.
CCutil_signal_handler
File:
UTIL/signal.c
Header:
util.h
Prototype:
int CCutil_signal_handler (int ccsignum, CCutil_handler handler)
Description:
-ccsignum is one of the CCutil_SIG* values defined in util.h
-handler is the new signal handler.
INSTALLS handler as the handler for ccsignum signals.
CCutil_handler is just a typedef for a pointer to a signal
handling function. It is a void (*)(int). The signal handler
is called whenever the signal is raised. The integer argument
passed to the signal handler is the signal number, in the
operating system's numbering. CCutil_sig_to_ccsig can be used
to convert this signal number into a CCutil_SIG* value.
CCutil_handler_fatal and CCutil_handler_warn are provided as
signal handlers for two common cases.
CCutil_signal_default
File:
UTIL/signal.c
Header:
util.h
Prototype:
int CCutil_signal_default (int ccsignum)
Description:
-ccsignum is one of the CCutil_SIG* values defined in util.h
RESTORES the default handling for ccsignum signals.
CCutil_signal_ignore
File:
UTIL/signal.c
Header:
util.h
Prototype:
int CCutil_signal_ignore (int ccsignum)
Description:
-ccsignum is one of the CCutil_SIG* values defined in util.h
IGNORES ccsignum signals.
CCutil_sig_to_ccsig
File:
UTIL/signal.c
Header:
util.h
Prototype:
int CCutil_sig_to_ccsig (int signum)
Description:
CONVERTS a signal number from the operating system's terms to
a CCutil_SIG* value. If there is no corresponding value, returns
-1.
CCutil_signal_init
File:
UTIL/signal.c
Header:
util.h
Prototype:
void CCutil_signal_init (void)
Description:
INITIALIZES signal handlers to CCutil_handler_fatal,
CCutil_handler_warn or CCutil_handler_exit as appropriate.
CCutil_handler_fatal
File:
UTIL/signal.c
Header:
util.h
Prototype:
void CCutil_handler_fatal (int signum)
Description:
HANDLES a signal by printing an error message, waiting a long
time to provide an opportunity to examine the program state with
a debugger, and then exiting. Designed to be used as a handler
argument to CCutil_signal_handler.
CCutil_handler_warn
File:
UTIL/signal.c
Header:
util.h
Prototype:
void CCutil_handler_warn (int signum)
Description:
HANDLES a signal by printing a warning message and continuing.
Designed to be used as a handler argument to CCutil_signal_handler.
CCutil_handler_exit
File:
UTIL/signal.c
Header:
util.h
Prototype:
void CCutil_handler_exit (int signum)
Description:
HANDLES a signal by printing a warning message and exiting.
Designed to be used as a handler argument to CCutil_signal_handler.
CCutil_sopen
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
CC_SFILE *CCutil_sopen (char *f, char *s)
Description:
Opens a file for buffered binary I/O. The buffered binary I/O
routines using CC_SFILE's attempt to be machine independent,
and only compatible with themselves. Comparable to the stdio
routine fopen(). If the file already exists and is being
opened for output, the old file is renamed by prepending an O
to is name.
f - the filename to open. "stdin" means descriptor 0, "stdout"
descriptor 1, and "stderr" descriptor 2. "-" means
descriptor 0 or 1, depending on wither the file is opened
for reading or writing.
s - the mode to open, either "r" for input, or "w" for output.
returns a pointer to the opened file, or NULL if there is an
error.
CCutil_sdopen
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
CC_SFILE *CCutil_sdopen (int d, char *s)
Description:
Opens a descriptor for buffered binary I/O. The buffered binary
I/O routines using CC_SFILE's attempt to be machine independent,
and only compatible with themselves. Comparable to the stdio
routine fdopen().
d - the descriptor to open.
s - the mode to open, either "r" for input, "w" for output, or
"rw" for both input and output.
returns a pointer to the opened file, or NULL if there is an
error.
CCutil_swrite
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_swrite (CC_SFILE *f, char *buf, int size)
Description:
writes to a buffered binary I/O file.
f - the CC_SFILE to write to
buf - the data to write
size - the number of bytes to write.
returns 0 if succesful, nonzero if failure.
CCutil_swrite_bits
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_swrite_bits (CC_SFILE *f, int x, int xbits)
Description:
writes bits to a buffered binary I/O file.
f - the CC_SFILE to write to
x - an int containing the data to write
xbits - the number of bits to write. The lowest order xbits
bits of x will be written.
returns 0 if succesful, nonzero if failure.
CCutil_swrite_ubits
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_swrite_ubits (CC_SFILE *f, unsigned int x, int xbits)
Description:
writes bits to a buffered binary I/O file.
f - the CC_SFILE to write to
x - an unsigned int int containing the data to write
xbits - the number of bits to write. The lowest order xbits
bits of x will be written.
returns 0 if succesful, nonzero if failure.
CCutil_swrite_char
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_swrite_char (CC_SFILE *f, char x)
Description:
writes a char to a buffered binary I/O file.
f - the CC_SFILE to write to
x - the char to write
returns 0 if succesful, nonzero if failure.
CCutil_swrite_string
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_swrite_string (CC_SFILE *f, const char *s)
Description:
writes a string to a buffered binary I/O file.
f - the CC_SFILE to write to
s - the string to write. The array of characters in s up to and
including the first NULL are written.
returns 0 if succesful, nonzero if failure.
CCutil_swrite_short
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_swrite_short (CC_SFILE *f, short x)
Description:
writes a short to a buffered binary I/O file.
f - the CC_SFILE to write to
x - the short to write
returns 0 if succesful, nonzero if failure.
CCutil_swrite_ushort
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_swrite_ushort (CC_SFILE *f, unsigned short x)
Description:
writes an unsigned short to a buffered binary I/O file.
f - the CC_SFILE to write to
x - the unsigned short to write
returns 0 if succesful, nonzero if failure.
CCutil_swrite_int
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_swrite_int (CC_SFILE *f, int x)
Description:
writes an int to a buffered binary I/O file.
f - the CC_SFILE to write to
x - the int to write
returns 0 if succesful, nonzero if failure.
CCutil_swrite_uint
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_swrite_uint (CC_SFILE *f, unsigned int x)
Description:
writes an unsigned int to a buffered binary I/O file.
f - the CC_SFILE to write to
x - the unsigned int to write
returns 0 if succesful, nonzero if failure.
CCutil_swrite_double
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_swrite_double (CC_SFILE *f, double x)
Description:
writes a double to a buffered binary I/O file.
f - the CC_SFILE to write to
x - the double to write
returns 0 if succesful, nonzero if failure.
CCutil_sread
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_sread (CC_SFILE *f, char *buf, int size)
Description:
reads from a buffered binary I/O file.
f - the CC_SFILE to read from.
buf - a buffer in which to store the data read. buf should have
space for size characters.
size - the number of bytes to read.
returns 0 if succesful, nonzero if failure.
CCutil_sread_bits
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_sread_bits (CC_SFILE *f, int *x, int xbits)
Description:
reads bits from a buffered binary I/O file.
f - the CC_SFILE to read from.
x - on return, will contain the bits read (in the low-order
xbits bits).
xbits - the number of bits read.
returns 0 if succesful, nonzero if failure.
CCutil_sread_ubits
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_sread_ubits (CC_SFILE *f, unsigned int *x, int xbits)
Description:
reads bits from a buffered binary I/O file.
f - the CC_SFILE to read from.
x - on return, will contain the bits read (in the low-order
xbits bits).
xbits - the number of bits read.
returns 0 if succesful, nonzero if failure.
CCutil_sread_char
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_sread_char (CC_SFILE *f, char *x)
Description:
reads a char from a buffered binary I/O file.
f - the CC_SFILE to read from.
x - on return, will contain the char read
returns 0 if succesful, nonzero if failure.
CCutil_sread_string
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_sread_string (CC_SFILE *f, char *x, int maxlen)
Description:
reads a string from a buffered binary I/O file.
f - the CC_SFILE to read from.
x - on return, will contain the string read.
maxlen - the maximum number of characters to read.
returns 0 if succesful, nonzero if failure.
CCutil_sread_short
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_sread_short (CC_SFILE *f, short *x)
Description:
reads a short from a buffered binary I/O file.
f - the CC_SFILE to read from.
x - on return, will contain the short read
returns 0 if succesful, nonzero if failure.
CCutil_sread_ushort
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_sread_ushort (CC_SFILE *f, unsigned short *x)
Description:
reads an unsigned short from a buffered binary I/O file.
f - the CC_SFILE to read from.
x - on return, will contain the unsigned short read
returns 0 if succesful, nonzero if failure.
CCutil_sread_short_r
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_sread_short_r (CC_SFILE *f, short *x)
Description:
reads a reversed short from a buffered binary I/O file.
f - the CC_SFILE to read from.
x - on return, will contain the short read
returns 0 if succesful, nonzero if failure.
CCutil_sread_short_r is provided for compatability with some
binary files written by other tools which use a different byte
order.
CCutil_sread_int
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_sread_int (CC_SFILE *f, int *x)
Description:
reads an int from a buffered binary I/O file.
f - the CC_SFILE to read from.
x - on return, will contain the int read
returns 0 if succesful, nonzero if failure.
CCutil_sread_uint
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_sread_uint (CC_SFILE *f, unsigned int *x)
Description:
reads an unsigned int from a buffered binary I/O file.
f - the CC_SFILE to read from.
x - on return, will contain the unsigned int read
returns 0 if succesful, nonzero if failure.
CCutil_sread_int_r
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_sread_int_r (CC_SFILE *f, int *x)
Description:
reads a reversed int from a buffered binary I/O file.
f - the CC_SFILE to read from.
x - on return, will contain the int read
returns 0 if succesful, nonzero if failure.
CCutil_sread_int_r is provided for compatability with some
binary files written by other tools which use a different byte
order.
CCutil_sread_double
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_sread_double (CC_SFILE *f, double *x)
Description:
reads a double from a buffered binary I/O file.
f - the CC_SFILE to read from.
x - on return, will contain the double read
returns 0 if succesful, nonzero if failure.
CCutil_sread_double_r
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_sread_double_r (CC_SFILE *f, double *x)
Description:
reads a reversed double from a buffered binary I/O file.
f - the CC_SFILE to read from.
x - on return, will contain the double read
returns 0 if succesful, nonzero if failure.
CCutil_sread_double_r is provided for compatability with some
binary files written by other tools which use a different byte
order.
CCutil_sflush
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_sflush (CC_SFILE *f)
Description:
flushes the buffer of a buffered binary I/O file.
f - the CC_SFILE to flush
returns 0 if succesful, nonzero if failure.
CCutil_stell
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_stell (CC_SFILE *f)
Description:
returns the current location in a buffered binary I/O file.
Comparable to the stdio function ftell().
f - the CC_SFILE
returns the current location, or -1 for failure.
CCutil_sseek
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_sseek (CC_SFILE *f, int offset)
Description:
changes the current location in a buffered binary I/O file.
Comparable to the stdio function fseek().
f - the CC_SFILE
offset - a value returned by CCutil_stell().
returns 0 for success, nonzero for failure.
CCutil_srewind
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_srewind (CC_SFILE *f)
Description:
changes the current location in a buffered binary I/O file to
the beginning. Comparable to the stdio function rewind().
f - the CC_SFILE
returns 0 for success, nonzero for failure.
CCutil_sclose
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_sclose (CC_SFILE *f)
Description:
closes a CC_SFILE.
f - the CC_SFILE to close
returns 0 for success, nonzero for failure.
CCutil_sbits
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_sbits (unsigned int x)
Description:
computes the number of bits necessary to represent all
nonnegative integers <= x
x - a number
returns the number of bits necessary to represent x.
CCutil_sdelete_file
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_sdelete_file (const char *fname)
Description:
deletes a file.
fname - the file to delete
returns 0 for success, nonzero for failure.
CCutil_sdelete_file_backup
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
int CCutil_sdelete_file_backup (const char *fname)
Description:
deletes the backup file for fname (created if fname was
overwritten by CCutil_sopen).
fname - the file name whose backup is to be deleted.
returns 0 for success, nonzero for failure.
CCutil_snet_open
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
CC_SFILE *CCutil_snet_open (char *h, unsigned short p)
Description:
Opens a network connection to a port on a remote host
h - the name of the host to connect to
p - the port on the host to connect to
returns a CC_SFILE (opened for input and output) for buffered
binary I/O to the specified port on the remote host,
or NULL if there is a failure.
Only exists if CC_NETREADY is defined
CCutil_snet_receive
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
CC_SFILE *CCutil_snet_receive (CC_SPORT *s)
Description:
Accepts a network connection on a port.
s - the CC_SPORT to accept a connection from. Must be the
returned result of a successfull CCutil_snet_listen call.
returns a CC_SFILE (opened for input and output) for buffered
binary I/O on the specified port, or NULL if there is a
failure.
Only exists if CC_NETREADY is defined
CCutil_snet_listen
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
CC_SPORT *CCutil_snet_listen (unsigned short p)
Description:
Prepares to accept network connections on a port.
p - the port on which to accept connections.
returns a CC_SPORT for accepting connections on the specified
port. This return value is passed to CCutil_snet_receive to
accept a connection. Returns NULL if there is a failure.
Only exists if CC_NETREADY is defined
CCutil_snet_unlisten
File:
UTIL/safe_io.c
Header:
util.h
Prototype:
void CCutil_snet_unlisten (CC_SPORT *s)
Description:
Ceases accepting network connections from an CC_SPORT.
s - the CC_SPORT to close.
Only exists if CC_NETREADY is defined
CCutil_priority_init
File:
UTIL/priority.c
Header:
util.h
Prototype:
int CCutil_priority_init (CCpriority *pri, int k)
Description:
-h should point to a CCpriority struct.
-k an initial allocation for the priority queue.
CCutil_priority_free
File:
UTIL/priority.c
Header:
util.h
Prototype:
void CCutil_priority_free (CCpriority *pri)
Description:
-frees the spaces allocated for the CCpriority queue.
CCutil_priority_findmin
File:
UTIL/priority.c
Header:
util.h
Prototype:
void *CCutil_priority_findmin (CCpriority *pri, double *keyval)
Description:
-returns the entry with least key value.
-returns NULL if no entries in heap.
-if (keyval != NULL), *keyval will be the minimum key value.
CCutil_priority_insert
File:
UTIL/priority.c
Header:
util.h
Prototype:
int CCutil_priority_insert (CCpriority *pri, void *data,
double keyval)
Description:
-adds (data, keyval) to h.
-returns a handle (>= 0) to use when deleting or changing the entry
-returns -1 if out of memory.
CCutil_priority_delete
File:
UTIL/priority.c
Header:
util.h
Prototype:
void CCutil_priority_delete (CCpriority *pri, int handle)
Description:
-deletes an entry from the queue. handle is the value returned by
CCutil_priority_insert.
CCutil_priority_deletemin
File:
UTIL/priority.c
Header:
util.h
Prototype:
void *CCutil_priority_deletemin (CCpriority *pri, double *keyval)
Description:
-like CCutil_priority_findmin, but also deletes the entry.
CCutil_priority_changekey
File:
UTIL/priority.c
Header:
util.h
Prototype:
void CCutil_priority_changekey (CCpriority *pri, int handle,
double newkey)
Description:
-changes the key of an entry in the queue. handle is the value
returned by CCutil_priority_insert.
CCutil_getdata
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_getdata (char *datname, int binary_in, int innorm,
int *ncount, CCdatagroup *dat, CCrandstate *rstate)
Description:
RETURNS the data to generate edge lengths in the dat structure.
The calling routine should be sure that dat points to
a structure. If datname is NULL then random entries will be
generated.
-datname is the name of the datfile or the matrix file, if NULL
then random data will be generated, according to the norm type.
For D2 and D3 norms, the coordinates will be uniform between 0
and ncount -1 (GEOGRAPHIC norms have x between -90 and 90 and y
between -180 and 180). (For D2, the points will be distinct.)
For MATRIX norms, the entries will be
uniform between 0 and MATRAND_SCALE * ncount - 1 (currently
10*ncount - 1. For CRYSTAL norms, a random matrix and bounds in
range of the TSPLIB problems is generated - the wavelength is
chosen to be 1.0, 1.35, or 1.70 depending on the ncount (but the
problem will not be very close to hitting ncount.).
-binary_in should be 1 if the datname file is in binary integers.
-innorm is the norm.
-ncount will return the number of nodes. If datname is NULL, then
ncount should be passed in with the number of nodes to be used in
the random problem generation.
-dat will contain the info to call the edgelen function.
CCutil_putmaster
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_putmaster (char *mastername, int ncount, CCdatagroup *dat,
int *perm)
Description:
WRITES the dat information and the permutation into a binary file.
This is used in the TSP, where the dat file has usually
been permuted to put the nodes into tour order.
-mastername is the name of the file (cannot be NULL)
-ncount is the number of nodes
-dat contains the edgelen info (e.g. x,y coordinates), it can be
NULL
-perm contains a permutation of 0 to ncount - 1 (so a tour in
node node node format)
CCutil_writemaster
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_writemaster (CC_SFILE *out, int ncount, CCdatagroup *dat,
int *perm)
Description:
WRITES the dat information and the permutation into a binary file.
This is used in the TSP, where the dat file has usually
been permuted to put the nodes into tour order.
-f is the CC_SFILE to write into
-ncount is the number of nodes
-dat contains the edgelen info (e.g. x,y coordinates), it can be
NULL
-perm contains a permutation of 0 to ncount - 1 (so a tour in
node node node format)
CCutil_getmaster
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_getmaster (char *mastername, int *ncount, CCdatagroup *dat,
int **perm)
Description:
RETURNS the dat information and the permutation from a binary file
(written by a call to CCutil_writemaster). Used by the TSP
code.
-mastername is the name of the file (cannot be NULL)
-ncount returns the number of nodes
-dat returns the edgelen info (e.g. x,y coordinates), or NULL
-perm returns a permutation of 0 to ncount - 1 (so a tour in
node node node format)
CCutil_readmaster
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_readmaster (CC_SFILE *in, int *ncount, CCdatagroup *dat,
int **perm)
Description:
RETURNS the dat information and the permutation from a binary file
(written by a call to CCutil_writemaster). Used by the TSP
code.
-f is the CC_SFILE to read from
-ncount returns the number of nodes
-dat returns the edgelen info (e.g. x,y coordinates), or NULL
-perm returns a permutation of 0 to ncount - 1 (so a tour in
node node node format)
CCutil_getnodeweights
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_getnodeweights (char *weightname, int ncount,
int weight_limit, double **wcoord, CCrandstate *rstate)
Description:
RETURNS a list of nonnegative nodesweights (they will be translated
if the weightname file has negative entries). If weightname
is NULL then random entries (from 0 to ncount - 1 will be
generated.
-weightname is the name of a file containing nodeweights. It will
only be read if inusenodeweights is 1. If NULL, random entries
will be generated (between 0 and weight_limit - 1)
-wcoord will contain the nonnegative node weights (it will be
here in CCutil_getnodeweights)
CCutil_gettsplib
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_gettsplib(char *datname, int *ncount, CCdatagroup *dat)
Description:
READS an xxx.tsp TSPLIB file, and returns the dat structure to
generate edge lengths.
-datname should be the name of a TSPLIB xxx.tsp file.
-ncount returns the number of nodes.
-dat returns the data.
CCutil_writetsplib
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_writetsplib (const char *fname, int ncount,
CCdatagroup *dat)
Description:
WRITES a TSPLIB file for the instance specified by dat.
CCutil_getedgelist
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_getedgelist (int ncount, char *fname, int *ecount,
int **elist, int **elen, int binary_in)
Description:
READS an edgelist in end1 end2 length format.
-fname name of the file
-ecount returns the number of edges
-elist returns the edges in end1 end2 format (it will be allocated
by CCutil_getedgelist)
-elen returns the length of the edges in len len len format
CCutil_getedgelist_n
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_getedgelist_n (int *ncount, char *fname, int *ecount,
int **elist, int **elen, int binary_in)
Description:
READS an edgelist in end1 end2 length format.
Like CCutil_getedgelist (), but it also returns ncount.
CCutil_genedgelist
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_genedgelist (int ncount, int ecount, int **elist,
int **elen, CCdatagroup *dat, int maxlen, CCrandstate *rstate)
Description:
GENERATES a random graph with ncount nodes and ecount edges, with
with edgelengths either determined by dat or random between 0 and
maxlen-1.
-dat specifies the function for computing the edge lengths (it can
be NULL.
-maxlen gives the range for random edge lengths (it is used if dat
is NULL.
CCutil_getcycle_edgelist
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_getcycle_edgelist (int ncount, char *cyclename,
int *outcycle, int binary_in)
Description:
READS a cycle in end1 end2 length format, and returns the cycle in
node node format in the array outcycle.
-outcycle should be allocated by the calling routine (and should
be at least ncount long)
CCutil_getcycle
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_getcycle (int ncount, char *cyclename, int *outcycle,
int binary_in)
Description:
READS a cycle in node node format, and returns the cycle in node
node format in the array outcycle.
-outcycle should be allocated by the calling routine
CCutil_cycle_len
File:
UTIL/getdata.c
Header:
util.h
Prototype:
void CCutil_cycle_len (int ncount, CCdatagroup *dat, int *cycle,
double *len)
Description:
COMPUTES the length of a cycle (in permutation format).
CCutil_getedges_double
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_getedges_double (int *ncount, char *fname, int *ecount,
int **elist, double **elen, int binary_in)
Description:
READS the edgelist in end1 end2 length format, where the length
is a double (used for x-vectors)
-returns the number of nodes
-fname is the name of the file to read.
-ecount returns the number of edges.
-elist returns the list of edges in end1 end2 format (it will be
allocated by CCutil_getedges_double).
-elen returns the lengths of the edges.
-binary_in indicates whether the file should be read in binary
or in ascii (1 is binary, 0 is ascii)
CCutil_writeedges
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_writeedges (int ncount, char *outedgename, int ecount,
int *elist, CCdatagroup *dat, int binary_out)
Description:
WRITES the edgelist in end1 end2 length format.
-ncount the number of nodes
-outedgename is the name of the file to write to.
-ecount is the number of edges.
-elist is the list of edges in end1 end2 format.
-dat contains the data to compute edgelengths.
-binary_in indicates whether the file should be written in binary
or in ascii (1 is binary, 0 is ascii)
CCutil_writecycle_edgelist
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_writecycle_edgelist (int ncount, char *outedgename,
int *cycle, CCdatagroup *dat, int binary_out)
Description:
WRITES the cycle in edgelist format.
CCutil_writecycle
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_writecycle (int ncount, char *outcyclename, int *cycle,
int binary_out)
Description:
WRITES the cycle in node node node format.
CCutil_writeedges_int
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_writeedges_int (int ncount, char *outedgename, int ecount,
int *elist, int *elen, int binary_out)
Description:
WRITES the edgelist in end1 end2 length format.
Like CCutil_writeedges, but lengths are specified in elen.
CCutil_writeedges_double
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_writeedges_double (int ncount, char *outedgename,
int ecount, int *elist, double *elen, int binary_out)
Description:
WRITES the edgelist in end1 end2 length format, where the length
is a double (used for x-vectors)
-ncount the number of nodes
-outedgename is the name of the file to write to.
-ecount is the number of edges.
-elist is the list of edges in end1 end2 format.
-elen are the lengths of the edges.
-binary_out indicates whether the file should be written in binary
or in ascii (1 is binary, 0 is ascii)
CCutil_datagroup_perm
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_datagroup_perm (int ncount, CCdatagroup *dat, int *perm)
Description:
reorders the nodes to match the order given in perm.
CCutil_copy_datagroup
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_copy_datagroup (int ncount, CCdatagroup *indat,
CCdatagroup *outdat)
Description:
COPIES indat to outdat.
CCutil_tri2dat
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_tri2dat (int ncount, int *elen, CCdatagroup *dat)
Description:
convert an upper triangular matrix of edge lengths to a CCdatagroup
CCutil_graph2dat_matrix
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_graph2dat_matrix (int ncount, int ecount, int *elist,
int *elen, int defaultlen, CCdatagroup *dat)
Description:
convert a matrix of edge lengths to a CCdatagroup
CCutil_graph2dat_sparse
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_graph2dat_sparse (int ncount, int ecount, int *elist,
int *elen, int defaultlen, CCdatagroup *dat)
Description:
BUILDS a datagroup from the edge list using the CC_SPARSE norm.
-dat will be filled in by the function.
-defaultlen gives the value for the non-edges (if it is <= 0, then
a default value of (max_edgelen + 1) * nnodes if fiven).
CCutil_get_sparse_dat_edges
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_get_sparse_dat_edges (int ncount, CCdatagroup *dat,
int *ecount, int **elist, int **elen)
Description:
GRABS the enitre set of edges in a CC_SPARSE datagroup. It returns
an error if the datagroup norm is not CC_SPARSE.
CCutil_sparse_strip_edges
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_sparse_strip_edges (CCdatagroup *dat, int in_ecount,
int *in_elist, int *in_elen, int *ecount, int **elist, int **elen)
Description:
REMOVES the artifical edges from in_elist.
-ecount, elist, and elen return the stripped edgelist.
CCutil_sparse_real_tour
File:
UTIL/getdata.c
Header:
util.h
Prototype:
int CCutil_sparse_real_tour (int ncount, CCdatagroup *dat, int *cyc,
int *yesno)
Description:
CHECKS whether each edge of cyc is in the CC_SPARSE datagroup.
-cyc gives a tour in node node node format.
-yesno will be set to 1 if it is a tour, and 0 otherwise.
CCutil_genhash_init
File:
UTIL/genhash.c
Header:
util.h
Prototype:
int CCutil_genhash_init (CCgenhash *h, int size,
int (*hcmp) (void *key1, void *key2, void *u_data),
unsigned int (*hfunc) (void *key, void *u_data),
void *u_data, double maxdensity, double lowdensity)
Description:
-CCgenhash *h (a pointer to a CCgenhash structure to be
initialized)
-int size (the initial size of the hash table)
-int (*hcmp) (void *key1, void *key2, void *u_data) (a pointer to
a function which returns 0 if key1 == key2, nonzero otherwise.
u_data will be the u_data passed to CCutil_genhash_init)
-unsigned int (*hfunc) (void *key, void *u_data) (a pointer to a
function which computes a hash function of key. u_data will be
the u_data passed to CCutil_genhash_init)
-void *u_data (a pointer which will be passed into hcmp and hfunc)
-double maxdensity (the maximum density (# elems / size) for the
hash table. When this density is reached the hash table is
expanded. 0.0 means never expand the hash table)
-double lowdensity (the density of a hash table immediately after
expansion)
RETURNS 0 for success, -1 if out of memory.
CCutil_genhash_free
File:
UTIL/genhash.c
Header:
util.h
Prototype:
void CCutil_genhash_free (CCgenhash *h, void (*freefunc)(void *k,
void *d, void *u_data))
Description:
-CCgenhash *h (a pointer to the hash table)
-void (*freefunc)(void *key, void *data, void *u_data) (a pointer
to a function to be called for each (key, data) pair in the
hashtable, or NULL)
ACTION: deletes all entries in h, and frees the space for h.
CCutil_genhash_u_data
File:
UTIL/genhash.c
Header:
util.h
Prototype:
void CCutil_genhash_u_data (CCgenhash *h, void *u_data)
Description:
-CCgenhash *h (a pointer to the hash table)
-void *u_data (a new value for u_data)
ACTION: changes the u_data stored with the hash table, and
passed to hcomp and hfunc)
CCutil_genhash_insert
File:
UTIL/genhash.c
Header:
util.h
Prototype:
int CCutil_genhash_insert (CCgenhash *h, void *key, void *data)
Description:
-CCgenhash *h (a pointer to the hash table)
-void *key (a pointer to the key data for this entry)
-void *data (the data to be stored)
ACTION: h[key] = data
COMMENT: if h[key] already has a value, this acts like a stack
CCutil_genhash_delete(key) will reveal the old value.
RETURNS 0 for success, -1 if out of memory.
CCutil_genhash_replace
File:
UTIL/genhash.c
Header:
util.h
Prototype:
int CCutil_genhash_replace (CCgenhash *h, void *key, void *data)
Description:
-CCgenhash *h (a pointer to the hash table)
-void *key (a pointer to the key data for this entry)
-void *data (the data to be stored)
ACTION: h[key] = data
COMMENT: if h[key] already has a value, this replaces that
value.
RETURNS 0 for success, -1 if out of memory.
CCutil_genhash_delete
File:
UTIL/genhash.c
Header:
util.h
Prototype:
int CCutil_genhash_delete (CCgenhash *h, void *key)
Description:
-CCgenhash *h (a pointer to the hash table)
-void *key (a pointer to the key data for this entry)
ACTION: h[key] = NULL
RETURNS 0 for success, -1 if h[key] was already NULL
CCutil_genhash_lookup
File:
UTIL/genhash.c
Header:
util.h
Prototype:
void *CCutil_genhash_lookup (CCgenhash *h, void *key)
Description:
-CCgenhash *h (a pointer to the hash table)
-void *key (a pointer to the key data for this entry)
RETURNS h[key], or NULL if h[key] not defined
CCutil_genhash_hash
File:
UTIL/genhash.c
Header:
util.h
Prototype:
unsigned int CCutil_genhash_hash (CCgenhash *h, void *key)
Description:
-CCgenhash *h (a pointer to the hash table)
-void *key (a pointer to key data)
RETURNS the hash function of key (ie, h->hfunc(key))
CCutil_genhash_insert_h
File:
UTIL/genhash.c
Header:
util.h
Prototype:
int CCutil_genhash_insert_h (CCgenhash *h, unsigned int hashval,
void *key, void *data)
Description:
alternate version of CCutil_genhash_insert, which takes an
additional argument, hashval, which should be equal to
CCutil_genhash_hash(key). This provides a method to avoid
recomputing CCutil_genhash_hash over multiple calls with the same
key
CCutil_genhash_replace_h
File:
UTIL/genhash.c
Header:
util.h
Prototype:
int CCutil_genhash_replace_h (CCgenhash *h, unsigned int hashval,
void *key, void *data)
Description:
alternate version of CCutil_genhash_replace, which takes an
additional argument, hashval, which should be equal to
CCutil_genhash_hash(key). This provides a method to avoid
recomputing CCutil_genhash_hash over multiple calls with the same
key.
CCutil_genhash_delete_h
File:
UTIL/genhash.c
Header:
util.h
Prototype:
int CCutil_genhash_delete_h (CCgenhash *h, unsigned int hashval,
void *key)
Description:
alternate version of CCutil_genhash_delete, which takes an
additional argument, hashval, which should be equal to
CCutil_genhash_hash(key). This provides a method to avoid
recomputing CCutil_genhash_hash over multiple calls with the same
key.
CCutil_genhash_lookup_h
File:
UTIL/genhash.c
Header:
util.h
Prototype:
int CCutil_genhash_lookup_h (CCgenhash *h, unsigned int hashval,
void *key)
Description:
alternate version of CCutil_genhash_lookup, which takes an
additional argument, hashval, which should be equal to
CCutil_genhash_hash(key). This provides a method to avoid
recomputing CCutil_genhash_hash over multiple calls with the same
key.
CCutil_genhash_start
File:
UTIL/genhash.c
Header:
util.h
Prototype:
void CCutil_genhash_start (CCgenhash *h, CCgenhash_iter *iter)
Description:
-CCgenhash *h (a pointer to the hash table)
-CCgenhash_iter *iter (a pointer to the iterator to be
initialized)
ACTION: initializes iter for iterating over elements of h using
CCutil_genhash_next()
CCutil_genhash_next
File:
UTIL/genhash.c
Header:
util.h
Prototype:
void *CCutil_genhash_next (CCgenhash *h, CCgenhash_iter *iter,
void **key, int *keysize)
Description:
-CCgenhash *h (a pointer to the hash table)
-CCgenhash_iter *iter (a pointer to an iterator)
-void **key (a pointer to a location for the key value)
-int *keysize (a pointer to a location for the key size)
RETURNS: a next data value from the hash table (corresponding
to the returned key and keysize), or NULL if there
are no more elements.
CCutil_genhash_next can tolerate the deletion of the current
(last returned) element and arbitrary lookups and replaces
between calls to CCutil_genhash_next. However, deletion of
elements other than the current one are not permitted, and
insertion a table which could be expanded can result in
elements being skipped.
CCutil_readint
File:
UTIL/fastread.c
Header:
util.h
Prototype:
int CCutil_readint (FILE *f)
Description:
- Returns the next int in the file f.
This is much faster that scanf. It is useful for big files and
and for profiling.
CCutil_edge_file_union
File:
UTIL/eunion.c
Header:
util.h
Prototype:
int CCutil_edge_file_union (int ncount, int nfiles, char **flist,
int *ecount, int **elist, int **elen, int *foundtour,
int *besttourlen)
Description:
MERGES a list of edge sets.
-ncount is the number of nodes.
-nfiles is the number of files to be read.
-flist is the list of the files.
-ecount, elist, elen returns the merged edge set.
-foundtour will return a 1 if at least one of the files is the
edgeset of a tour (it can be NULL).
-besttour will return the length of the best tour amongst the
edge sets (it can be NULL)
Returns a nonzero value if there was and error.
CCutil_edge_to_cycle
File:
UTIL/edgeutil.c
Header:
util.h
Prototype:
int CCutil_edge_to_cycle (int ncount, int *elist, int *yesno,
int *cyc)
Description:
CONVERTS an edgelist to a cycle.
-ncount is the number of nodes.
-elist is an edgelist in end1 end2 format.
-yesno returns 1 if elist describes a tour and 0 otherwise.
-cyc returns the cycle in permutation format if it is not NULL
(if cyc is not NULL, then it should point to an array of
length at least ncount).
Returns a nonzero value if there was an error.
CCelist_init
File:
UTIL/edgeutil.c
Header:
util.h
Prototype:
void CCelist_init (CCelist *elist)
Description:
initialize a CCelist
CCelistl_init
File:
UTIL/edgeutil.c
Header:
util.h
Prototype:
void CCelistl_init (CCelistl *elist)
Description:
initialize a CCelistl
CCelistw_init
File:
UTIL/edgeutil.c
Header:
util.h
Prototype:
void CCelistw_init (CCelistw *elist)
Description:
initialize a CCelistw
CCelistlw_init
File:
UTIL/edgeutil.c
Header:
util.h
Prototype:
void CCelistlw_init (CCelistlw *elist)
Description:
initialize a CCelistlw
CCelist_free
File:
UTIL/edgeutil.c
Header:
util.h
Prototype:
void CCelist_free (CCelist *elist)
Description:
free a CCelist
CCelistl_free
File:
UTIL/edgeutil.c
Header:
util.h
Prototype:
void CCelistl_free (CCelistl *elist)
Description:
free a CCelistl
CCelistw_free
File:
UTIL/edgeutil.c
Header:
util.h
Prototype:
void CCelistw_free (CCelistw *elist)
Description:
free a CCelistw
CCelistlw_free
File:
UTIL/edgeutil.c
Header:
util.h
Prototype:
void CCelistlw_free (CCelistlw *elist)
Description:
free a CCelistlw
CCelist_alloc
File:
UTIL/edgeutil.c
Header:
util.h
Prototype:
int CCelist_alloc (CCelist *elist, int ecount)
Description:
allocate space for a CCelist
CCelistl_alloc
File:
UTIL/edgeutil.c
Header:
util.h
Prototype:
int CCelistl_alloc (CCelistl *elist, int ecount)
Description:
allocate space for a CCelistl
CCelistw_alloc
File:
UTIL/edgeutil.c
Header:
util.h
Prototype:
int CCelistw_alloc (CCelistw *elist, int ecount)
Description:
allocate space for a CCelistw
CCelistlw_alloc
File:
UTIL/edgeutil.c
Header:
util.h
Prototype:
int CCelistlw_alloc (CCelistlw *elist, int ecount)
Description:
CCelistlw
CCutil_dat_setnorm
File:
UTIL/edgelen.c
Header:
util.h
Prototype:
int CCutil_dat_setnorm (CCdatagroup *dat, int norm)
Description:
NOTES:
Supported norms (with defs in edgelen.h) are:
CC_MAXNORM - the L-infinity norm
CC_EUCLIDEAN_CEIL - the norm for the plaXXXX problems
CC_EUCLIDEAN - rounded L-2 norm
CC_EUCLIDEAN_3D - rounded L-2 norm in 3 space
CC_USER - a norm specified by the user
CC_GEOGRAPHIC - distances on a sphere (Groetshel and
Holland)
CC_ATT - pseudo-Euclidean norm for att532
CC_MATRIXNORM - complete graph (lower + diagonal matrix)
CC_DSJRANDNORM - random edgelengths
CC_CRYSTAL - Bland-Shallcross xray norm
- The coordinates generated for CC_CRYSTAL problems
(in CCutil_getdata.c) have been diveded by the motor
speeds (this makes the edgelen function faster) and
scaled by CRYSTAL_SCALE (currently 10000) and rounded to
the nearest integer (this lets the edgelen function
produce integer lengths without further rounding). The
result is a closer approximation to the Bland -
Shallcross floating point length function than that
given in TSPLIB_1.2.
CC_SPARSE - a sparse graph
CC_RHMAPx - where x = 1, 2, 3, 4, 5 one of 5 RH mapping
norms.
If CCUTIL_EDGELEN_FUNCTIONPTR has been defined in util.h,
then CCutil_dat_edgelen is a pointer to a function instead of
a function. This saves a function call and results in
improved performance on some machines for edgelen-intensive
routines like linkern. The function pointer is set by
CCutil_dat_setnorm.
IMPORTANT: This means that if CCUTIL_EDGELEN_FUNCTIONPTR is set
and you have more than one CCdatagroup, you must call
CCutil_dat_setnorm whenever you switch from using one
CCdatagroup to the other. IF YOU DON'T DO THIS, EDGELEN WILL
RETURN INCORRECT RESULTS. For this reason,
CCUTIL_EDGELEN_FUNCTIONPTR should only be set with extreme
caution.
To define a user norm, you must perform the following steps:
1. In util.h, define the struct CCdata_user to contain the data
necessary for the computation of edge lengths.
2. In edgelen.c, write the init_userdat and free_userdat functions
which initialize and free a CCdata_user structure.
3. In edgelen.c, write the user_edgelen function which
computes the length of the edge for node i to node j, using the
userdat field of the CCdatagroup argument (userdat is of type
CCdata_user).
4. In getdata.c, write the build_user, read_user_text,
read_user_binary, readmaster_user, and writemaster_user
routines. read_user_text reads the data file which provides
the data for computing the edge lengths. build_user and
read_user_binary are optional routines which build random
datasets and read binary datafiles. writemaster_user writes a
binary version of that data to the master file, and
readmaster_user reads that same data. See the comments before
those routines in getdata for more details on what they should
do.
5. In getdata.c, write permute_user, which permutes the data to
reflect a permutation of the nodes.
CCutil_dat_edgelen
File:
UTIL/edgelen.c
Header:
util.h
Prototype:
int CCutil_dat_edgelen (int i, int j, CCdatagroup *dat)
Description:
compute the length of an edge
CCutil_dsjrand_init
File:
UTIL/edgelen.c
Header:
util.h
Prototype:
void CCutil_dsjrand_init (CCdatagroup *dat, int maxdist, int seed)
Description:
initialize the dsjrand norm
CCutil_dat_getnorm
File:
UTIL/edgelen.c
Header:
util.h
Prototype:
void CCutil_dat_getnorm (CCdatagroup *dat, int *norm)
Description:
get the norm of a CCdatagroup
CCutil_init_datagroup
File:
UTIL/edgelen.c
Header:
util.h
Prototype:
void CCutil_init_datagroup (CCdatagroup *dat)
Description:
initialize a CCdatagroup
CCutil_freedatagroup
File:
UTIL/edgelen.c
Header:
util.h
Prototype:
void CCutil_freedatagroup (CCdatagroup *dat)
Description:
free a CCdatagroup
CCutil_dheap_init
File:
UTIL/dheaps_i.c
Header:
util.h
Prototype:
int CCutil_dheap_init (CCdheap *h, int k)
Description:
-h should point to a CCdheap struct.
-k the max number of elements in the dheap.
NOTES:
A k-element heap will malloc 16k bytes of memory. If memory is
tight, using integer keys (instead of doubles), brings it down to
12k bytes, and if arbitrary deletions are not required, with a
little rewriting, the h->loc field can be eliminated, bring the
space down to 8k bytes.
These routines work with indices into the h->key array, so in
some cases, you will need to maintain a separate names array to know
what element belongs to index i. For an example, see the k_nearest
code in kdnear.c.
CCutil_dheap_free
File:
UTIL/dheaps_i.c
Header:
util.h
Prototype:
void CCutil_dheap_free (CCdheap *h)
Description:
-frees the spaces allocated by CCutil_dheap_init
CCutil_dheap_resize
File:
UTIL/dheaps_i.c
Header:
util.h
Prototype:
int CCutil_dheap_resize (CCdheap *h, int newsize)
Description:
-REALLOCs h so it can contain newsize elements.
-returns -1 if it can't resize the heap.
CCutil_dheap_findmin
File:
UTIL/dheaps_i.c
Header:
util.h
Prototype:
int CCutil_dheap_findmin (CCdheap *h)
Description:
-returns the index of the element with min value h->key[i]
-returns -1 if no elements in heap.
CCutil_dheap_insert
File:
UTIL/dheaps_i.c
Header:
util.h
Prototype:
int CCutil_dheap_insert (CCdheap *h, int i)
Description:
-inserts the element with index i (so its key should be loaded
beforehand in h->key[i]).
CCutil_dheap_delete
File:
UTIL/dheaps_i.c
Header:
util.h
Prototype:
void CCutil_dheap_delete (CCdheap *h, int i)
Description:
-deletes the element with index i.
CCutil_dheap_deletemin
File:
UTIL/dheaps_i.c
Header:
util.h
Prototype:
int CCutil_dheap_deletemin (CCdheap *h)
Description:
-returns the min element in the heap, and deletes the min element
-returns -1 if no elements in heap.
CCutil_dheap_changekey
File:
UTIL/dheaps_i.c
Header:
util.h
Prototype:
void CCutil_dheap_changekey (CCdheap *h, int i, double newkey)
Description:
-changes the key of the element with index i to newkey.
CCutil_bix_getopt
File:
UTIL/bgetopt.c
Header:
util.h
Prototype:
int CCutil_bix_getopt (int argc, char **argv, const char *def,
int *p_optind, char **p_optarg)
Description:
parse an argument list
CCutil_allocrus
File:
UTIL/allocrus.c
Header:
util.h
Prototype:
void *CCutil_allocrus (size_t size)
Description:
RETURNS a pointer to an allocated block of "size" memory.
CCutil_freerus
File:
UTIL/allocrus.c
Header:
util.h
Prototype:
void CCutil_freerus (void *ptr)
Description:
FREES ptr.
CCutil_reallocrus
File:
UTIL/allocrus.c
Header:
util.h
Prototype:
void *CCutil_reallocrus (void *ptr, size_t size)
Description:
REALLOCS ptr to size bytes.
CCutil_reallocrus_scale
File:
UTIL/allocrus.c
Header:
util.h
Prototype:
int CCutil_reallocrus_scale (void **pptr, int *pnnum, int count,
double scale, size_t size)
Description:
void **pptr (a reference to the pointer to the allocated space)
int *pnnum (a reference to the number of objects in the
allocated space)
int count (a minimum value for the new nnum)
double scale (a scale factor to apply to nnum)
int size (the size of objects to be realloced)
RETURNS 0 if *pptr was successfully changed to point to at
least max(*pnnum*scale, *pnnum+1000, count) objects.
*pnnum is changed to the new object count.
Otherwise, prints an error message, leaves *pptr and
*pnnum alone, and returns nonzero.
CCutil_reallocrus_count
File:
UTIL/allocrus.c
Header:
util.h
Prototype:
int CCutil_reallocrus_count (void **pptr, int count,
size_t size)
Description:
void **pptr (a reference to the pointer to the allocated space)
int count (number of objects to be realloced)
int size (the size of the objects to be realloced)
RETURNS 0 is successful, and 1 if the realloc failed.
CCutil_bigchunkalloc
File:
UTIL/allocrus.c
Header:
util.h
Prototype:
CCbigchunkptr *CCutil_bigchunkalloc (void)
Description:
RETURNS a CCbigchunkptr with the "this_one" field loaded with a
a pointer to a bigchunk of memory.
NOTES:
The idea is to use bigchunks (the size of a bigchunk is defined
by CC_BIGCHUNK in util.h) to supply local routines with memory
for ptrs, so the memory can be shared with other
local routines.
CCutil_bigchunkfree
File:
UTIL/allocrus.c
Header:
util.h
Prototype:
CCutil_bigchunkfree (CCbigchunkptr *bp)
Description:
ACTION: Frees a CCbigchunkptr.
CCptrworld_init
File:
UTIL/allocrus.c
Header:
util.h
Prototype:
void CCptrworld_init (CCptrworld *world)
Description:
initialize a CCptrworld with 1 reference
CCptrworld_add
File:
UTIL/allocrus.c
Header:
util.h
Prototype:
void CCptrworld_add (CCptrworld *world)
Description:
add a reference to a CCptrworld
CCptrworld_delete
File:
UTIL/allocrus.c
Header:
util.h
Prototype:
void CCptrworld_delete (CCptrworld *world)
Description:
delete a reference to a ptrworld, and free if no more references
CCutil_edgehash_init
File:
UTIL/edgemap.c
Header:
util.h
Prototype:
int CCutil_edgehash_init (CCutil_edgehash *h, int size)
Description:
MISSING
CCutil_edgehash_add
File:
UTIL/edgemap.c
Header:
util.h
Prototype:
int CCutil_edgehash_add (CCutil_edgehash *h, int end1, int end2,
int val)
Description:
MISSING
CCutil_edgehash_set
File:
UTIL/edgemap.c
Header:
util.h
Prototype:
int CCutil_edgehash_set (CCutil_edgehash *h, int end1, int end2,
int val)
Description:
MISSING
CCutil_edgehash_del
File:
UTIL/edgemap.c
Header:
util.h
Prototype:
int CCutil_edgehash_del (CCutil_edgehash *h, int end1, int end2)
Description:
MISSING
CCutil_edgehash_find
File:
UTIL/edgemap.c
Header:
util.h
Prototype:
int CCutil_edgehash_find (CCutil_edgehash *h, int end1, int end2,
int *val)
Description:
MISSING
CCutil_edgehash_getall
File:
UTIL/edgemap.c
Header:
util.h
Prototype:
int CCutil_edgehash_getall (CCutil_edgehash *h, int *ecount,
int **elist, int **elen);
Description:
MISSING
CCutil_edgehash_delall
File:
UTIL/edgemap.c
Header:
util.h
Prototype:
void CCutil_edgehash_delall (CCutil_edgehash *h)
Description:
MISSING
CCutil_edgehash_free
File:
UTIL/edgemap.c
Header:
util.h
Prototype:
void CCutil_edgehash_free (CCutil_edgehash *h)
Description:
MISSING
CC_SAFE_MALLOC
File:
INCLUDE/util.h
Header:
util.h
Prototype:
CC_SAFE_MALLOC(nnum,type)
Description:
int nnum (the number of objects to be malloced)
data type (the sort of objects to be malloced)
RETURNS a pointer to the allocated space. If out of memory,
it prints an error message and returns NULL.
CC_FREE
File:
INCLUDE/util.h
Header:
util.h
Prototype:
CC_FREE(object,type)
Description:
type *object (pointer to previously allocated space)
data type (the sort of object)
ACTION: frees the memory and sets the object to NULL.
CC_IFFREE
File:
INCLUDE/util.h
Header:
util.h
Prototype:
CC_IFFREE(object,type)
Description:
type *object (pointer to previously allocated space)
data type (the sort of object)
ACTION: if *object is not NULL, frees the memory and sets
the object to NULL.
CC_PTR_ALLOC_ROUTINE
File:
INCLUDE/util.h
Header:
util.h
Prototype:
CC_PTR_ALLOC_ROUTINE (type, functionname, chunklist, freelist)
Description:
data type (the sort of objects)
string functionname (the generated function)
CCbigchunkptr *chunklist (used to accumulate bigchunks)
type *freelist (used for the linked list of objects)
ACTION: Generates a function ("functionname") that returns
(type *) objects, keeping the free ones on freelist
and getting its space from calls to
CCutil_bigchunkalloc.
CC_PTR_FREE_ROUTINE
File:
INCLUDE/util.h
Header:
util.h
Prototype:
CC_PTR_FREE_ROUTINE (type, functionname, freelist)
Description:
Parameters as above.
ACTION: Generates a function that adds an object to the
freelist.
CC_PTR_FREE_LIST_ROUTINE
File:
INCLUDE/util.h
Header:
util.h
Prototype:
CC_PTR_FREE_LIST_ROUTINE (type, functionname, freefunction)
Description:
Parameters defined as above, with freefunction the function
generated by CC_PTR_FREE_ROUTINE.
ACTION: Generates a function to free a linked list of
objects using calls to freefunction.
CC_PTR_FREE_WORLD_ROUTINE
File:
INCLUDE/util.h
Header:
util.h
Prototype:
CC_PTR_FREE_WORLD_ROUTINE (type, functionname, chunklist, freelist)
Description:
Parameters defined as above.
ACTION: Generates a function that returns all of the
memory used in the CC_PTR_ALLOC_ROUTINE allocations
back to the global supply of CCbigchunkptrs.
CC_PTR_LEAKS_ROUTINE
File:
INCLUDE/util.h
Header:
util.h
Prototype:
CC_PTR_LEAKS_ROUTINE (type, name, chunklist, freelist, field,
fieldtype)
Description:
As above, with "field" the name of a "fieldtype" field in the
object type that can be set to 0 or to 1.
ACTION: Generates a function that checks to see that we have
not leaked any of the objects.
CC_PTR_STATUS_ROUTINE
File:
INCLUDE/util.h
Header:
util.h
Prototype:
CC_PTR_STATUS_ROUTINE (type, name, chunklist, freelist)
Description:
ACTION: Like LEAKS, but does not check for duplicates (and so
does not corrupt the objects).
NOTES:
These routines use the functions in allocrus.c. The PTR macros
generate the functions for allocating objects for linked lists. They
get their raw memory from the bigchunk supply, so foo_free_world
(generated by CC_PTR_FREE_WORLD_ROUTINE) should be called for each
type of linked object "foo" when closing down the local memory.
To use these functions, put the macros near the top of the file
before any calls to the functions (since the macros also write the
function prototypes). If you use CC_PTR_FREE_LIST_ROUTINE for foo,
you must also use CC_PTR_FREE_ROUTINE, and
CC_PTR_FREE_LIST_ROUTINE must be listed after CC_PTR_FREE_ROUTINE
(to get the prototype).