4b9cdf9d6a3854dc2fe2153197e88e82dbedb6d7 kent Sun Mar 31 10:45:18 2013 -0700 Separating into sections with heavyweight comments. diff --git src/inc/common.h src/inc/common.h index 7b8cee1..99f5e16 100644 --- src/inc/common.h +++ src/inc/common.h @@ -331,32 +331,32 @@ void reverseInts(int *a, int length); /* Reverse the order of the integer array. */ void reverseUnsigned(unsigned *a, int length); /* Reverse the order of the unsigned array. */ void reverseDoubles(double *a, int length); /* Reverse the order of the double array. */ void reverseStrings(char **a, int length); /* Reverse the order of the char* array. */ void swapBytes(char *a, char *b, int length); /* Swap buffers a and b. */ -/* Some things to manage simple lists - structures that begin - * with a pointer to the next element in the list. */ +/******* Some things to manage simple lists - structures that begin ****** + ******* with a pointer to the next element in the list. ******/ struct slList { struct slList *next; }; int slCount(const void *list); /* Return # of elements in list. */ void *slElementFromIx(void *list, int ix); /* Return the ix'th element in list. Returns NULL * if no such element. */ int slIxFromElement(void *list, void *el); /* Return index of el in list. Returns -1 if not on list. */ @@ -436,88 +436,72 @@ // Merges and sorts a pair of singly linked lists leaving only unique // items via slUniqufy. duplicate itens are defined by the compare routine // returning 0. If free is provided, items dropped from list can disposed of. boolean slRemoveEl(void *vpList, void *vToRemove); /* Remove element from doubly linked list. Usage: * slRemove(&list, el); * Returns TRUE if element in list. */ void slFreeList(void *listPt); /* Free all elements in list and set list pointer to null. * Usage: * slFreeList(&list); */ +/******* slInt - an int on a list - the first of many singly linked list structures *******/ + struct slInt /* List of integers. */ { struct slInt *next; /* Next in list. */ int val; /* Integer value. */ }; struct slInt *slIntNew(int x); #define newSlInt slIntNew /* Return a new double. */ int slIntCmp(const void *va, const void *vb); /* Compare two slInts. */ int slIntCmpRev(const void *va, const void *vb); /* Compare two slInts in reverse direction. */ struct slInt * slIntFind(struct slInt *list, int target); /* Find target in slInt list or return NULL */ -void doubleSort(int count, double *array); -/* Sort an array of doubles. */ - -double doubleMedian(int count, double *array); -/* Return median value in array. This will sort - * the array as a side effect. */ - -void doubleBoxWhiskerCalc(int count, double *array, double *retMin, - double *retQ1, double *retMedian, double *retQ3, double *retMax); -/* Calculate what you need to draw a box and whiskers plot from an array of doubles. */ +/******* slDouble - a double on a list *******/ struct slDouble /* List of double-precision numbers. */ { struct slDouble *next; /* Next in list. */ double val; /* Double-precision value. */ }; struct slDouble *slDoubleNew(double x); #define newSlDouble slDoubleNew /* Return a new int. */ int slDoubleCmp(const void *va, const void *vb); /* Compare two slDoubles. */ double slDoubleMedian(struct slDouble *list); /* Return median value on list. */ -void slDoubleBoxWhiskerCalc(struct slDouble *list, double *retMin, - double *retQ1, double *retMedian, double *retQ3, double *retMax); -/* Calculate what you need to draw a box and whiskers plot from a list of slDoubles. */ - -void intSort(int count, int *array); -/* Sort an array of ints. */ - -int intMedian(int count, int *array); -/* Return median value in array. This will sort - * the array as a side effect. */ +/******* slName - a zero terminated string on a list *******/ struct slName /* List of names. The name array is allocated to accommodate full name */ { struct slName *next; /* Next in list. */ char name[1]; /* Allocated at run time to length of string. */ }; struct slName *newSlName(char *name); #define slNameNew newSlName /* Return a new slName. */ #define slNameFree freez @@ -589,55 +573,59 @@ struct slName *slNameListFromStringArray(char *stringArray[], int arraySize); /* Return list of slNames from an array of strings of length arraySize. * If a string in the array is NULL, the array will be treated as * NULL-terminated. */ char *slNameListToString(struct slName *list, char delimiter); /* Return string created by joining all names with the delimiter. */ struct slName *slNameLoadReal(char *fileName); /* load file lines that are not blank or start with a '#' into a slName * list */ struct slName *slNameIntersection(struct slName *a, struct slName *b); /* return intersection of two slName lists. */ +/******* slRef - a void pointer on a list *******/ + struct slRef /* Singly linked list of generic references. */ { struct slRef *next; /* Next in list. */ void *val; /* A reference to something. */ }; struct slRef *slRefNew(void *val); /* Create new slRef element. */ struct slRef *refOnList(struct slRef *refList, void *val); /* Return ref if val is already on list, otherwise NULL. */ void refAdd(struct slRef **pRefList, void *val); /* Add reference to list. */ void refAddUnique(struct slRef **pRefList, void *val); /* Add reference to list if not already on list. */ void slRefFreeListAndVals(struct slRef **pList); /* Free up (with simple freeMem()) each val on list, and the list itself as well. */ struct slRef *refListFromSlList(void *list); /* Make a reference list that mirrors a singly-linked list. */ +/******* slPair - a name/value pair on list where value not always a string *******/ + struct slPair /* A name/value pair. */ { struct slPair *next; /* Next in list. */ char *name; /* Name of item. */ void *val; /* Pointer to item data. */ }; struct slPair *slPairNew(char *name, void *val); /* Allocate new name/value pair. */ void slPairAdd(struct slPair **pList, char *name, void *val); /* Add new slPair to head of list. */ void slPairFree(struct slPair **pEl); @@ -694,34 +682,63 @@ void slPairValSort(struct slPair **pList); /* Sort slPair list on values (must be string). */ int slPairIntCmp(const void *va, const void *vb); // Compare two slPairs on their integer values. void slPairIntSort(struct slPair **pList); // Sort slPair list on integer values. int slPairAtoiCmp(const void *va, const void *vb); // Compare two slPairs on their strings interpreted as integer values. void slPairValAtoiSort(struct slPair **pList); // Sort slPair list on string values interpreted as integers. + + +/******* Some old stuff maybe we could trim. *******/ + void gentleFree(void *pt); /* check pointer for NULL before freeing. * (Actually plain old freeMem does that these days.) */ +/******* Some math stuff *******/ + +void doubleSort(int count, double *array); +/* Sort an array of doubles. */ + +double doubleMedian(int count, double *array); +/* Return median value in array. This will sort + * the array as a side effect. */ + +void doubleBoxWhiskerCalc(int count, double *array, double *retMin, + double *retQ1, double *retMedian, double *retQ3, double *retMax); +/* Calculate what you need to draw a box and whiskers plot from an array of doubles. */ + +void slDoubleBoxWhiskerCalc(struct slDouble *list, double *retMin, + double *retQ1, double *retMedian, double *retQ3, double *retMax); +/* Calculate what you need to draw a box and whiskers plot from a list of slDoubles. */ + +int intMedian(int count, int *array); +/* Return median value in array. This will sort + * the array as a side effect. */ + +void intSort(int count, int *array); +/* Sort an array of ints. */ + + /******* Some stuff for processing strings. *******/ char *cloneStringZ(const char *s, int size); /* Make a zero terminated copy of string in memory */ char *cloneString(const char *s); /* Make copy of string in dynamic memory */ char *cloneLongString(char *s); /* Make clone of long string. */ char *catTwoStrings(char *a, char *b); /* Allocate new string that is a concatenation of two strings. */ int differentWord(char *s1, char *s2);