1 /* 2 * KeyListOpsMethods.h 3 * 4 * Created on: Feb 6, 2014 5 * Author: nek3d 6 */ 7 8 #ifndef KEYLISTOPSMETHODS_H_ 9 #define KEYLISTOPSMETHODS_H_ 10 11 #include <map> 12 #include <utility> //for pair 13 #include "string.h" 14 #include <stdint.h> 15 #include "RecordKeyVector.h" 16 17 using namespace std; 18 19 class KeyListOpsMethods { 20 public: 21 KeyListOpsMethods(); 22 KeyListOpsMethods(RecordKeyVector *keyList, int column = 1); 23 ~KeyListOpsMethods(); 24 setIsBam(bool isBam)25 void setIsBam(bool isBam) { _isBam = isBam; } setKeyList(RecordKeyVector * keyList)26 void setKeyList(RecordKeyVector *keyList) { _keyList = keyList; } setColumn(int col)27 void setColumn(int col) { _column = col; } setNullValue(const string & nullVal)28 void setNullValue(const string & nullVal) { _nullVal = nullVal; } getNullValue()29 const string &getNullValue() const { return _nullVal; } setDelimStr(const string & delimStr)30 void setDelimStr(const string &delimStr) { _delimStr = delimStr; } getDelimStr()31 const string &getDelimStr() const { return _delimStr; } 32 33 // return the total of the values in the vector 34 double getSum(); 35 // return the average value in the vector 36 double getMean(); 37 // return the standard deviation 38 double getStddev(); 39 // return the sample standard deviation 40 double getSampleStddev(); 41 // return the median value in the vector 42 double getMedian(); 43 // return the most common value in the vector 44 const string &getMode(); 45 // return the least common value in the vector 46 const string &getAntiMode(); 47 // return the minimum element of the vector 48 double getMin(); 49 // return the maximum element of the vector 50 double getMax(); 51 // return the minimum absolute value of the vector 52 double getAbsMin(); 53 // return the maximum absolute value of the vector 54 double getAbsMax(); 55 // return the count of element in the vector 56 uint32_t getCount(); 57 // return a the count of _unique_ elements in the vector 58 uint32_t getCountDistinct(); 59 // return only those elements that occur once 60 const string &getDistinctOnly(); 61 // as distinct, but sorted numerically. 62 const string &getDistinctSortNum(bool ascending = true); 63 // as distinct, but sorted numerically, descending 64 65 66 // return a delimiter-separated list of elements 67 const string & getCollapse(const string & delimiter = ","); 68 // return a concatenation of all elements in the vector 69 const string & getConcat(); 70 // return a comma-separated list of the _unique_ elements 71 const string & getDistinct(); 72 // return a histogram of values and their freqs. in desc. order of frequency 73 const string & getFreqDesc(); 74 // return a histogram of values and their freqs. in asc. order of frequency 75 const string & getFreqAsc(); 76 // return the first value in the list 77 const string & getFirst(); 78 // return the last value in the list 79 const string & getLast(); 80 nonNumErrFlagSet()81 bool nonNumErrFlagSet() const { return _nonNumErrFlag; } getErrMsg()82 const string &getErrMsg() const { return _errMsg; } resetNonNumErrFlag()83 void resetNonNumErrFlag() { 84 _nonNumErrFlag = false; 85 _errMsg.clear(); 86 } 87 88 private: 89 RecordKeyVector *_keyList; 90 int _column; 91 string _nullVal; 92 string _delimStr; 93 string _retStr; 94 95 RecordKeyVector _nullKeyList; //this has to exist just so we can initialize _iter, below. 96 RecordKeyVector::iterator_type _iter; 97 98 // Some methods need to put values into a vector, mostly for sorting. 99 vector<double> _numArray; 100 vector<string> _qsArray; 101 102 typedef map<string, int> freqMapType; 103 freqMapType _freqMap; 104 freqMapType::iterator _freqIter; 105 106 typedef enum { UNSORTED, ASC, DESC} SORT_TYPE; 107 108 bool _nonNumErrFlag; 109 string _errMsg; 110 bool _isBam; 111 112 typedef multimap<int, string, less<int> > histAscType; 113 typedef multimap<int, string, greater<int> > histDescType; 114 void init(); 115 const string &getColVal(); 116 double getColValNum(); empty()117 bool empty() { return _keyList->empty(); } begin()118 void begin() { _iter = _keyList->begin(); } end()119 bool end() { return _iter == _keyList->end(); } next()120 void next() { _iter = _keyList->next(); } 121 void toArray(bool useNum, SORT_TYPE sortVal = UNSORTED); 122 void sortArray(bool useNum, bool ascOrder); 123 void makeFreqMap(); 124 125 126 }; 127 128 129 #endif /* KEYLISTOPSMETHODS_H_ */ 130