COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libcoopy_core/include/coopy/FVal.h
Go to the documentation of this file.
00001 #ifndef COOPY_FVAL
00002 #define COOPY_FVAL
00003 
00004 #include <set>
00005 
00006 #include <coopy/SparseSheet.h>
00007 
00008 namespace coopy {
00009   namespace cmp {
00010     class FSingleVal;
00011     class FMultiVal;
00012   }
00013 }
00014 
00015 class coopy::cmp::FSingleVal {
00016 public:
00017   int index;
00018   int index2;
00019 
00020   FSingleVal() {
00021     index = -1;
00022     index2 = -1;
00023   }
00024 
00025   void setIndex(int idx, bool alt) {
00026     if (alt) {
00027       if (index2==-1) {
00028         index2 = idx;
00029       } else {
00030         if (index2!=idx) {
00031           index2 = -2;
00032           index = -2;
00033         }
00034       }
00035     } else {
00036       if (index==-1) {
00037         index = idx;
00038       } else {
00039         if (index!=idx) {
00040           index = -2;
00041           index2 = -2;
00042         }
00043       }
00044     }
00045   }
00046   
00047   void apply(coopy::store::SparseFloatSheet& match,int row) {
00048     if (index>=0) {
00049       match.cell(index,row)++;
00050     }
00051   }
00052 };
00053 
00054 
00055 class coopy::cmp::FMultiVal {
00056 public:
00057   std::set<int> indices, indices2;
00058   //size_t len2;
00059 
00060   FMultiVal() {
00061     //len2 = 0;
00062   }
00063 
00064   void setIndex(int idx, bool alt) {
00065     if (alt) {
00066       if (indices2.size()<50) {
00067         indices2.insert(idx);
00068       }
00069       //if (len2<50) len2++;
00070     } else {
00071       if (indices.size()<50) {
00072         indices.insert(idx);
00073       }
00074     }
00075   }
00076 
00077   void apply(coopy::store::SparseFloatSheet& match,int row) {
00078     size_t len = indices.size();
00079     size_t len2 = indices2.size();
00080     if (len2>len) len = len2;
00081     if (len<=0) return;
00082     if (len>=50) return;
00083     float delta = 1.0/len;
00084     for (std::set<int>::const_iterator it=indices.begin();
00085          it!=indices.end();
00086          it++) {
00087       match.cell(*it,row)+=delta;
00088     }
00089   }
00090 };
00091 
00092 
00093 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines