Index: /trunk/psLib/src/collections/Makefile
===================================================================
--- /trunk/psLib/src/collections/Makefile	(revision 436)
+++ /trunk/psLib/src/collections/Makefile	(revision 437)
@@ -3,5 +3,5 @@
 endif
 
-TARGET = libpsDataManip.a
+TARGET = libpsCollections.a
 
 all: $(TARGET)
@@ -10,8 +10,10 @@
 
 SRC_OBJS = \
-    psArray.o
+    psArray.o \
+    psBitMask.o \
+    psSort.o \
 
-libpsDataManip.a: $(SRC_OBJS)
-	$(AR) -r libpsDataManip.a $(SRC_OBJS)
+libpsCollections.a: $(SRC_OBJS)
+	$(AR) -r libpsCollections.a $(SRC_OBJS)
 
 install: $(TARGET)
Index: /trunk/psLib/src/collections/psBitMask.c
===================================================================
--- /trunk/psLib/src/collections/psBitMask.c	(revision 437)
+++ /trunk/psLib/src/collections/psBitMask.c	(revision 437)
@@ -0,0 +1,138 @@
+#include "psBitMask.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <ctype.h>
+
+static char* getByte(int bit, const psBitMask* inMask);
+static char mask(int bit);
+
+psBitMask* psBitMaskAlloc(int n)
+{
+    psBitMask *newObj = (psBitMask*)malloc(sizeof(psBitMask));
+    newObj->n = n;
+    newObj->bits = (char*)malloc(sizeof(char)*n);
+    memset(newObj->bits, n, 0);
+    
+    return newObj;
+}
+
+void psBitMaskFree(psBitMask *restrict inMask)
+{
+    free(inMask->bits);
+    free(inMask);
+}
+
+psBitMask* psBitMaskSet(psBitMask *inMask, int bit)
+{
+    char* byte = getByte(bit, inMask);
+    *byte |= mask(bit);
+    
+    return inMask;
+}
+
+int psBitMaskTest(const psBitMask *inMask, int bit)
+{
+    char* byte = getByte(bit, inMask);
+    if((*byte&mask(bit)) == 0) {
+        return 0;
+    }
+    
+    return 1;
+}
+
+psBitMask* psBitMaskOp(psBitMask *outMask, const psBitMask *restrict inMask1, char *operator, const psBitMask *restrict inMask2)
+{
+    int i = 0;
+    int n = 0;
+    char tempChar = '0';
+    char *outBits = NULL;
+    char *inBits1 = NULL;
+    char *inBits2 = NULL;
+
+    if(outMask == NULL) {
+        printf("Null output psBitMask\n");
+        return outMask;
+    }
+    
+    if(inMask1 == NULL) {
+        printf("Null input psBitMask1\n");
+        return outMask;
+    }
+    
+    if(operator == NULL) {
+        printf("Null input operator\n");
+        return outMask;
+
+    }
+ 
+    if(inMask2 == NULL) {
+        printf("Null input psBitMask2\n");
+        return outMask;
+    }
+    
+    if(inMask1->n != inMask2->n || outMask->n != inMask1->n) {
+        printf("Mask sizes not the same\n");
+        return outMask;
+    }
+    
+    n = outMask->n;
+    outBits = outMask->bits;
+    inBits1 = inMask1->bits;
+    inBits2 = inMask2->bits;
+    
+    tempChar = toupper(*operator);
+    switch(tempChar) {
+    case 'A':
+        for(i=0; i<n; i++) {
+            outBits[i] = inBits1[i] & inBits2[i];
+        }
+        break;
+    case 'O':
+        for(i=0; i<n; i++) {
+            outBits[i] = inBits1[i] | inBits2[i];
+        }
+        break;
+    case 'X':
+        for(i=0; i<n; i++) {
+            outBits[i] = inBits1[i] ^ inBits2[i];
+        }
+        break;
+    default:
+        printf("Invalid psBitMask option %s\n", operator);
+    }
+    
+    return outMask;
+}
+
+char *psBitMaskToString(const psBitMask *restrict inMask)
+{
+    int i = 0;
+    int numBits = inMask->n*8;
+    char* outString = (char*)malloc(numBits);
+    for(i=0; i<numBits; i++) {
+        outString[numBits-i-1] = (psBitMaskTest(inMask, i))?'1':'0';
+    }
+    
+    return outString;
+}
+
+/* 0 based index of byte array's byte that contains containing bit */
+static char* getByte(int bit, const psBitMask* inMask)
+{
+    int index = 0;
+    char *byte = 0;
+    index = bit/8;
+    byte = inMask->bits+index;
+    
+    return byte;
+}
+
+static char mask(int bit)
+{
+    char mask = 0x01;
+    mask = mask << (bit%8);
+    
+    return mask;
+}
Index: /trunk/psLib/src/collections/psBitMask.h
===================================================================
--- /trunk/psLib/src/collections/psBitMask.h	(revision 437)
+++ /trunk/psLib/src/collections/psBitMask.h	(revision 437)
@@ -0,0 +1,13 @@
+typedef struct {
+    int n;
+    char *bits;
+} psBitMask;
+
+psBitMask* psBitMaskAlloc(int n);
+void psBitMaskFree(psBitMask *restrict inMask);
+psBitMask* psBitMaskSet(psBitMask *inMask, int bit);
+int psBitMaskTest(const psBitMask *inMask, int bit);
+psBitMask* psBitMaskOp(psBitMask *outMask, const psBitMask *restrict inMask1, char *operator, const psBitMask *restrict inMask2);
+char *psBitMaskToString(const psBitMask *restrict inMask);
+static char* getByte(int bit, const psBitMask* inMask);
+static char mask(int bit);
Index: /trunk/psLib/src/collections/psSort.c
===================================================================
--- /trunk/psLib/src/collections/psSort.c	(revision 437)
+++ /trunk/psLib/src/collections/psSort.c	(revision 437)
@@ -0,0 +1,145 @@
+#include "psArray.h"
+#include "psSort.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <float.h>
+/*       qsort - sorts an array */
+/*       The  qsort()  function sorts an array with nmemb elements of size size.
+       The base argument points to the start of the array.
+
+       The contents of the array are sorted in ascending order according to  a
+       comparison  function  pointed  to  by  compar, which is called with two
+       arguments that point to the objects being compared.
+
+       The comparison function must return an integer less than, equal to,  or
+       greater  than  zero  if  the first argument is considered to be respec-
+       tively less than, equal to, or greater than the second.  If two members
+       compare as equal, their order in the sorted array is undefined.
+*/
+static int psCompare(const void *x, const void *y);
+
+
+psFloatArray *psSort(psFloatArray *restrict outArray, const psFloatArray *restrict inArray)
+{
+    int inN = 0;
+    int outN = 0;
+    int i = 0;
+    int elSize = 0;
+    float *inArr = NULL;
+    float *outArr = NULL;
+
+    if(outArray == NULL) {
+        printf("NULL output array n");
+        return outArray;
+    }
+    
+    if(inArray == NULL) {
+        printf("NULL input array\n");
+        return outArray;
+    }
+        
+    // Initialize values
+    inN = inArray->n;
+    outN = outArray->n;
+    inArr = inArray->arr;
+    outArr = outArray->arr;
+    elSize = sizeof(float);
+    
+    if(inN != outN) {
+        printf("Input and output array sizes are not equal");
+        return outArray;
+    }
+    
+    // Copy input array values into output array
+    for(i=0; i<inN; i++) {
+        outArr[i] = inArr[i];
+    }
+    
+    // Sort output array
+    qsort((void*)outArr, inN, elSize, psCompare);
+    
+    return outArray;
+}
+
+psIntArray *psSortIndex(psIntArray *restrict outArray, const psFloatArray *restrict inArray)
+{
+    int inN = 0;
+    int outN = 0;
+    int i = 0;
+    int j = 0;
+    float tempVal = 0.0f;
+    float *inArr = NULL;
+    int *outArr = NULL;
+    float diff = 0.0f;
+    psFloatArray *tmpFloatArray = NULL;
+    
+    if(outArray == NULL) {
+        printf("NULL output array n");
+        return outArray;
+    }
+    
+    if(inArray == NULL) {
+        printf("NULL input array\n");
+        return outArray;
+    }
+
+    // Initialize values
+    inN = inArray->n;
+    outN = outArray->n;
+    inArr = inArray->arr;
+    outArr = outArray->arr;
+
+    if(inN != outN) {
+        printf("Input and output array sizes are not equal");
+        return outArray;
+    }
+
+    tmpFloatArray = psFloatArrayAlloc(inN);
+    tmpFloatArray = psSort(tmpFloatArray, inArray);
+    
+    for(i=0; i<inN; i++) {
+        tempVal = tmpFloatArray->arr[i];
+        for(j=0; j<inN; j++) {
+            diff = fabsf(tempVal - inArr[j]);
+            if(diff < FLT_EPSILON) {
+                outArr[i] = j;
+                break;
+            }
+        } 
+    }
+    
+    // Free temp memory
+    psFreeFloatArray(tmpFloatArray);
+    
+    return outArray;    
+}
+
+static int psCompare(const void *x, const void *y)
+{
+    float *item1 = NULL;
+    float *item2 = NULL;
+    
+    if(x == NULL || y == NULL) {
+        printf("Null input argument\n");
+    }
+    
+    item1 = (float*)x;
+    item2 = (float*)y;
+    
+    if(item1 == NULL || item2 == NULL) {
+        printf("Improper cast to float\n");
+    }
+    
+    if(*item1 < *item2) {
+        return -1;
+    }
+    else if(*item1 > *item2) {
+        return 1;
+    }
+    else {
+        return 0;
+    }
+}
Index: /trunk/psLib/src/collections/psSort.h
===================================================================
--- /trunk/psLib/src/collections/psSort.h	(revision 437)
+++ /trunk/psLib/src/collections/psSort.h	(revision 437)
@@ -0,0 +1,2 @@
+psFloatArray *psSort(psFloatArray *restrict out, const psFloatArray *restrict inArray);
+psIntArray *psSortIndex(psIntArray *restrict out, const psFloatArray *restrict inArray);
