Changeset 578 for trunk/psLib/src/collections/psBitSet.h
- Timestamp:
- May 5, 2004, 10:43:57 AM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/collections/psBitSet.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psBitSet.h
r542 r578 1 /** @file psBit Mask.h1 /** @file psBitSet.h 2 2 * 3 * @brief Creates an array of b its of arbitrary length.3 * @brief Creates an array of bytes of arbitrary length for storing individual bits. 4 4 * 5 * Bit masks are useful for turning options on and off. This module provides functions to create an array of 6 * bits of arbitrary length and manipulate them with basic binary operations. A print function is also 7 * provided to display the entire set of bits in binary form. 5 * Bit masks are useful tools for toggling various flags and options. This set of functions module provides 6 * a mechanism to create an array of bits of arbitrary length and manipulate them with basic binary 7 * operations. A print function is also provided to display the entire set of bits in binary format as a 8 * string. 8 9 * 9 10 * @author Ross Harman, MHPCC 10 11 * 11 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-0 4-28 17:47:56$12 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-05-05 20:43:57 $ 13 14 * 14 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 15 16 */ 16 17 17 #ifndef PSBIT MASK_H18 #define PSBIT MASK_H18 #ifndef PSBITSET_H 19 #define PSBITSET_H 19 20 20 21 /******************************************************************************/ … … 22 23 /******************************************************************************/ 23 24 24 /** Struct containing array of b its and itslength.25 /** Struct containing array of bytes to hold bit data and corresponding array length. 25 26 * 26 27 * The bits in the struct are assembled in as an array of bytes with eight bits per byte. The bits are 27 * arranged with the LSB in first position of the first array element.28 * arranged with the LSB in first (right most) position of the first array element. 28 29 */ 29 30 typedef struct … … 32 33 char *bits; /**< Aray of bytes holding bits */ 33 34 } 34 psBit Mask;35 psBitSet; 35 36 36 37 /*****************************************************************************/ … … 38 39 /*****************************************************************************/ 39 40 40 /** Allocate a psBit Mask.41 /** Allocate a psBitSet. 41 42 * 42 * Create a psBitMask with number of bytes specified by the user. All bits are set to zero upon allocation. 43 * Create a psBitSet with the number of bytes specified by the user. All bits are set to zero upon 44 * allocation. 43 45 * 44 * @return psBit Mask*: Pointer to struct containing array of bits and size of array.46 * @return psBitSet*: Pointer to struct containing array of bits and size of array. 45 47 */ 46 psBit Mask* psBitMaskAlloc(47 int n /**< Number of bytes in array */48 psBitSet* psBitSetAlloc( 49 int n /**< Number of bytes in psBitSet array */ 48 50 ); 49 51 50 /** Free a psBit Mask52 /** Free a psBitSet 51 53 * 52 * Deletes a psBit Mask array and its byte count.54 * Deletes a psBitSet array. 53 55 */ 54 void psBit MaskFree(55 psBit Mask *restrict inMask /**< Pointer to psBitMask struct to be deleted. */56 void psBitSetFree( 57 psBitSet *restrict inMask /**< Pointer to psBitSet to be deleted. */ 56 58 ); 57 59 58 60 /** Set a bit. 59 61 * 60 * Sets a bit at a given bit location . The bit is set based on a zero index with the first bit set in61 * the zero bit slot of the zero element of the byte array. As an example, setting bit 3 in an array with62 * two elements would result in an psBitMaskthat looks like 00000000 00001000.62 * Sets a bit at a given bit location, either one or zero. The bit is set based on a zero index with the 63 * first bit set in the zero bit slot of the zero element of the byte array. As an example, setting bit 3 in 64 * an array with two elements would result in an psBitSet that looks like 00000000 00001000. 63 65 * 64 * @return psBit Mask*: Pointer to struct containing array with bit set.66 * @return psBitSet*: Pointer to struct containing psBitSet. 65 67 */ 66 psBit Mask* psBitMaskSet(67 psBit Mask *inMask, /**< Pointer to struct to be set. */68 int bit /**< Bit to be set. */68 psBitSet* psBitSetSet( 69 psBitSet *restrict inMask, /**< Pointer to psBitSet to be set. */ 70 int bit /**< Bit to be set. */ 69 71 ); 70 72 71 73 /** Test the value of a bit. 72 74 * 73 * Prints the value of a bit at a given bit location. The bit printed based on a zero index with the first 74 * 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 75 * two elements that looks like 00000000 00001000 would retrun a value of one, since that value was already set. 75 * Prints the value of a bit at a given bit location, either one or zero. The resulting bit is based on a 76 * zero index format with the first bit set in the zero bit slot of the zero element of the byte array 77 * As an example, testing bit 3 in a psBitSet with two bytes that looks like 00000000 00001000 would return a 78 * value of one, since that is the value that was set. 76 79 * 77 80 * @return int: Value of bit, either one or zero. 78 81 */ 79 int psBit MaskTest(80 const psBit Mask *inMask, /**< Pointer to struct to be tested. */81 int bit /**< Bit to be tested. */82 int psBitSetTest( 83 const psBitSet *restrict inMask, /**< Pointer psBitSet to be tested. */ 84 int bit /**< Bit to be tested. */ 82 85 ); 83 86 84 /** Perform a binary operation on two psBit Masks87 /** Perform a binary operation on two psBitSets 85 88 * 86 * Perform an AND, OR, or XOR on two psBit Masks. If the BitMasks are not the same size, the operation will not87 * be performed and an error message will be printed.89 * Perform an AND, OR, or XOR on two psBitSets. If the BitMasks are not the same size, the operation will not 90 * be performed and an error message will be logged. 88 91 * 89 * @return psBit Mask*: Pointer to struct containing result of binary operation.92 * @return psBitSet*: Pointer to struct containing result of binary operation. 90 93 */ 91 psBit Mask* psBitMaskOp(92 psBit Mask *outMask, /**< Resulting psBitMaskfrom binary operation */93 const psBit Mask *restrict inMask1, /**< First psBitMaskon which to operate */94 char *operator, /**< Bit operation */95 const psBit Mask *restrict inMask2 /**< First psBitMaskon which to operate */94 psBitSet* psBitSetOp( 95 psBitSet *restrict outMask, /**< Resulting psBitSet from binary operation */ 96 const psBitSet *restrict inMask1, /**< First psBitSet on which to operate */ 97 char *operator, /**< Bit operation */ 98 const psBitSet *restrict inMask2 /**< First psBitSet on which to operate */ 96 99 ); 97 100 98 /** Print the contents of a psBitMask.101 /** Convert the psBitSet to a string of ones and zeros. 99 102 * 100 * Prints the contents of a psBitMask in its binary form of ones and zeros. The LSB is the left-most chracter. 103 * Converts the contents of a psBitSet to a string representation of its binary form of ones and zeros. The 104 * LSB is the right-most chracter. Each set of eight characters represents one byte. 101 105 * 102 * @return char*: Pointer to character array containing binary formatteddata.106 * @return char*: Pointer to character array containing string data. 103 107 */ 104 char *psBitMaskToString( 105 const psBitMask *restrict inMask /**< psBitMask to print */ 106 ); 107 108 /** Private function to return a byte. 109 * 110 * Finds the byte containing the bit within the byte array. 111 * 112 * @return char*: Pointer to byte in which bit is contained. 113 */ 114 static char* getByte( 115 int bit, /**< Bit to index to search. */ 116 const psBitMask *restrict inMask /**< psBitMask to search. */ 117 ); 118 119 /** Private function to create a mask. 120 * 121 * Creates an eight bit mask with the given bit set. All other bits in the byte are zero. The input bit uses 122 * zero-based indexing, and is the cumulitive index within the array, not the localized byte's bit position. 123 * 124 * @return char*: Pointer to byte in which bit is contained. 125 */ 126 static char mask( 127 int bit /**< Bit to set within mask */ 108 char *psBitSetToString( 109 const psBitSet *restrict inMask /**< psBitSet to convert */ 128 110 ); 129 111
Note:
See TracChangeset
for help on using the changeset viewer.
