Index: /trunk/psLib/src/collections/psBitSet.c
===================================================================
--- /trunk/psLib/src/collections/psBitSet.c	(revision 542)
+++ /trunk/psLib/src/collections/psBitSet.c	(revision 542)
@@ -0,0 +1,160 @@
+/** @file  psBitMask.c
+ *
+ *  @brief Creates an array of bits of arbitrary length.
+ *
+ *  Bit masks are useful for turning options on and off. This module provides functions to create an array of 
+ *  bits of arbitrary length and manipulate them with basic binary operations. A print function is also 
+ *  provided to display the entire set of bits in binary form.
+ *
+ *  @author Ross Harman, MHPCC
+ *   
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-04-28 17:47:24 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ */
+
+/******************************************************************************/
+/*  INCLUDE FILES                                                             */
+/******************************************************************************/
+#include <string.h>
+#include <stdio.h>
+#include <ctype.h>
+
+#include "psBitMask.h"
+#include "psMemory.h"
+
+/*****************************************************************************/
+/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
+/*****************************************************************************/
+static char* getByte(int bit, const psBitMask *restrict 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;
+}
+
+/*****************************************************************************/
+/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
+/*****************************************************************************/
+psBitMask* psBitMaskAlloc(int n)
+{
+    psBitMask *newObj = psAlloc(sizeof(psBitMask));
+    newObj->n = n;
+    newObj->bits = psAlloc(sizeof(char)*n);
+    memset(newObj->bits, n, 0);
+
+    return newObj;
+}
+
+void psBitMaskFree(psBitMask *restrict inMask)
+{
+    psFree(inMask->bits);
+    psFree(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;
+}
Index: /trunk/psLib/src/collections/psBitSet.h
===================================================================
--- /trunk/psLib/src/collections/psBitSet.h	(revision 542)
+++ /trunk/psLib/src/collections/psBitSet.h	(revision 542)
@@ -0,0 +1,130 @@
+/** @file  psBitMask.h
+ *
+ *  @brief Creates an array of bits of arbitrary length.
+ *
+ *  Bit masks are useful for turning options on and off. This module provides functions to create an array of 
+ *  bits of arbitrary length and manipulate them with basic binary operations. A print function is also 
+ *  provided to display the entire set of bits in binary form.
+ *
+ *  @author Ross Harman, MHPCC
+ *   
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-04-28 17:47:56 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ */
+
+#ifndef PSBITMASK_H
+#define PSBITMASK_H
+
+/******************************************************************************/
+/*  TYPE DEFINITIONS                                                          */
+/******************************************************************************/
+
+/** Struct containing array of bits and its length.
+ *
+ *  The bits in the struct are assembled in as an array of bytes with eight bits per byte. The bits are 
+ *  arranged with the LSB in first position of the first array element.
+ */
+typedef struct
+{
+    int n;      /**< Number of bytes in the array */
+    char *bits; /**< Aray of bytes holding bits */
+}
+psBitMask;
+
+/*****************************************************************************/
+/* FUNCTION PROTOTYPES                                                       */
+/*****************************************************************************/
+
+/** Allocate a psBitMask.
+ *
+ *  Create a psBitMask with number of bytes specified by the user. All bits are set to zero upon allocation.
+ *
+ *  @return  psBitMask*: Pointer to struct containing array of bits and size of array.
+ */
+psBitMask* psBitMaskAlloc(
+    int n   /**< Number of bytes in array */
+);
+
+/** Free a psBitMask
+ *
+ *  Deletes a psBitMask array and its byte count.
+ */
+void psBitMaskFree(
+    psBitMask *restrict inMask  /**< Pointer to psBitMask struct to be deleted. */
+);
+
+/** Set a bit.
+ *
+ *  Sets a bit at a given bit location. The bit is set based on a zero index with the first bit set in 
+ *  the zero bit slot of the zero element of the byte array. As an example, setting bit 3 in an array with
+ *  two elements would result in an psBitMask that looks like 00000000 00001000.
+ *
+ *  @return  psBitMask*: Pointer to struct containing array with bit set.
+ */
+psBitMask* psBitMaskSet(
+    psBitMask *inMask, /**< Pointer to struct to be set. */
+    int bit            /**< Bit to be set. */
+);
+
+/** Test the value of a bit.
+ *
+ *  Prints the value of a bit at a given bit location. The bit printed based on a zero index with the first 
+ *  bit set in the zero bit slot of the zero element of the byte array. As an example, testing bit 3 in an array with
+ *  two elements that looks like 00000000 00001000 would retrun a value of one, since that value was already set.
+ *
+ *  @return  int: Value of bit, either one or zero.
+ */
+int psBitMaskTest(
+    const psBitMask *inMask,    /**< Pointer to struct to be tested. */
+    int bit                     /**< Bit to be tested. */
+);
+
+/** Perform a binary operation on two psBitMasks
+ *
+ *  Perform an AND, OR, or XOR on two psBitMasks. If the BitMasks are not the same size, the operation will not
+ *  be performed and an error message will be printed.
+ *
+ *  @return  psBitMask*: Pointer to struct containing result of binary operation.
+ */
+psBitMask* psBitMaskOp(
+    psBitMask *outMask,                 /**< Resulting psBitMask from binary operation */
+    const psBitMask *restrict inMask1,  /**< First psBitMask on which to operate */
+    char *operator,                     /**< Bit operation */
+    const psBitMask *restrict inMask2   /**< First psBitMask on which to operate */
+);
+
+/** Print the contents of a psBitMask.
+ *
+ *  Prints the contents of a psBitMask in its binary form of ones and zeros. The LSB is the left-most chracter.
+ *
+ *  @return  char*: Pointer to character array containing binary formatted data.
+ */
+char *psBitMaskToString(
+    const psBitMask *restrict inMask /**< psBitMask to print */
+);
+
+/** Private function to return a byte.
+ *
+ *  Finds the byte containing the bit within the byte array.
+ *
+ *  @return  char*: Pointer to byte in which bit is contained.
+ */
+static char* getByte(
+    int bit,                            /**< Bit to index to search. */
+    const psBitMask *restrict inMask    /**< psBitMask to search. */
+);
+
+/** Private function to create a mask.
+ *
+ *  Creates an eight bit mask with the given bit set. All other bits in the byte are zero. The input bit uses
+ *  zero-based indexing, and is the cumulitive index within the array, not the localized byte's bit position.
+ *
+ *  @return  char*: Pointer to byte in which bit is contained.
+ */
+static char mask(
+    int bit /**< Bit to set within mask */
+);
+
+#endif
Index: /trunk/psLib/src/types/psBitSet.c
===================================================================
--- /trunk/psLib/src/types/psBitSet.c	(revision 542)
+++ /trunk/psLib/src/types/psBitSet.c	(revision 542)
@@ -0,0 +1,160 @@
+/** @file  psBitMask.c
+ *
+ *  @brief Creates an array of bits of arbitrary length.
+ *
+ *  Bit masks are useful for turning options on and off. This module provides functions to create an array of 
+ *  bits of arbitrary length and manipulate them with basic binary operations. A print function is also 
+ *  provided to display the entire set of bits in binary form.
+ *
+ *  @author Ross Harman, MHPCC
+ *   
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-04-28 17:47:24 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ */
+
+/******************************************************************************/
+/*  INCLUDE FILES                                                             */
+/******************************************************************************/
+#include <string.h>
+#include <stdio.h>
+#include <ctype.h>
+
+#include "psBitMask.h"
+#include "psMemory.h"
+
+/*****************************************************************************/
+/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
+/*****************************************************************************/
+static char* getByte(int bit, const psBitMask *restrict 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;
+}
+
+/*****************************************************************************/
+/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
+/*****************************************************************************/
+psBitMask* psBitMaskAlloc(int n)
+{
+    psBitMask *newObj = psAlloc(sizeof(psBitMask));
+    newObj->n = n;
+    newObj->bits = psAlloc(sizeof(char)*n);
+    memset(newObj->bits, n, 0);
+
+    return newObj;
+}
+
+void psBitMaskFree(psBitMask *restrict inMask)
+{
+    psFree(inMask->bits);
+    psFree(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;
+}
Index: /trunk/psLib/src/types/psBitSet.h
===================================================================
--- /trunk/psLib/src/types/psBitSet.h	(revision 542)
+++ /trunk/psLib/src/types/psBitSet.h	(revision 542)
@@ -0,0 +1,130 @@
+/** @file  psBitMask.h
+ *
+ *  @brief Creates an array of bits of arbitrary length.
+ *
+ *  Bit masks are useful for turning options on and off. This module provides functions to create an array of 
+ *  bits of arbitrary length and manipulate them with basic binary operations. A print function is also 
+ *  provided to display the entire set of bits in binary form.
+ *
+ *  @author Ross Harman, MHPCC
+ *   
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-04-28 17:47:56 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ */
+
+#ifndef PSBITMASK_H
+#define PSBITMASK_H
+
+/******************************************************************************/
+/*  TYPE DEFINITIONS                                                          */
+/******************************************************************************/
+
+/** Struct containing array of bits and its length.
+ *
+ *  The bits in the struct are assembled in as an array of bytes with eight bits per byte. The bits are 
+ *  arranged with the LSB in first position of the first array element.
+ */
+typedef struct
+{
+    int n;      /**< Number of bytes in the array */
+    char *bits; /**< Aray of bytes holding bits */
+}
+psBitMask;
+
+/*****************************************************************************/
+/* FUNCTION PROTOTYPES                                                       */
+/*****************************************************************************/
+
+/** Allocate a psBitMask.
+ *
+ *  Create a psBitMask with number of bytes specified by the user. All bits are set to zero upon allocation.
+ *
+ *  @return  psBitMask*: Pointer to struct containing array of bits and size of array.
+ */
+psBitMask* psBitMaskAlloc(
+    int n   /**< Number of bytes in array */
+);
+
+/** Free a psBitMask
+ *
+ *  Deletes a psBitMask array and its byte count.
+ */
+void psBitMaskFree(
+    psBitMask *restrict inMask  /**< Pointer to psBitMask struct to be deleted. */
+);
+
+/** Set a bit.
+ *
+ *  Sets a bit at a given bit location. The bit is set based on a zero index with the first bit set in 
+ *  the zero bit slot of the zero element of the byte array. As an example, setting bit 3 in an array with
+ *  two elements would result in an psBitMask that looks like 00000000 00001000.
+ *
+ *  @return  psBitMask*: Pointer to struct containing array with bit set.
+ */
+psBitMask* psBitMaskSet(
+    psBitMask *inMask, /**< Pointer to struct to be set. */
+    int bit            /**< Bit to be set. */
+);
+
+/** Test the value of a bit.
+ *
+ *  Prints the value of a bit at a given bit location. The bit printed based on a zero index with the first 
+ *  bit set in the zero bit slot of the zero element of the byte array. As an example, testing bit 3 in an array with
+ *  two elements that looks like 00000000 00001000 would retrun a value of one, since that value was already set.
+ *
+ *  @return  int: Value of bit, either one or zero.
+ */
+int psBitMaskTest(
+    const psBitMask *inMask,    /**< Pointer to struct to be tested. */
+    int bit                     /**< Bit to be tested. */
+);
+
+/** Perform a binary operation on two psBitMasks
+ *
+ *  Perform an AND, OR, or XOR on two psBitMasks. If the BitMasks are not the same size, the operation will not
+ *  be performed and an error message will be printed.
+ *
+ *  @return  psBitMask*: Pointer to struct containing result of binary operation.
+ */
+psBitMask* psBitMaskOp(
+    psBitMask *outMask,                 /**< Resulting psBitMask from binary operation */
+    const psBitMask *restrict inMask1,  /**< First psBitMask on which to operate */
+    char *operator,                     /**< Bit operation */
+    const psBitMask *restrict inMask2   /**< First psBitMask on which to operate */
+);
+
+/** Print the contents of a psBitMask.
+ *
+ *  Prints the contents of a psBitMask in its binary form of ones and zeros. The LSB is the left-most chracter.
+ *
+ *  @return  char*: Pointer to character array containing binary formatted data.
+ */
+char *psBitMaskToString(
+    const psBitMask *restrict inMask /**< psBitMask to print */
+);
+
+/** Private function to return a byte.
+ *
+ *  Finds the byte containing the bit within the byte array.
+ *
+ *  @return  char*: Pointer to byte in which bit is contained.
+ */
+static char* getByte(
+    int bit,                            /**< Bit to index to search. */
+    const psBitMask *restrict inMask    /**< psBitMask to search. */
+);
+
+/** Private function to create a mask.
+ *
+ *  Creates an eight bit mask with the given bit set. All other bits in the byte are zero. The input bit uses
+ *  zero-based indexing, and is the cumulitive index within the array, not the localized byte's bit position.
+ *
+ *  @return  char*: Pointer to byte in which bit is contained.
+ */
+static char mask(
+    int bit /**< Bit to set within mask */
+);
+
+#endif
