00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _SCOREACCUMULATOR_HPP
00014 #define _SCOREACCUMULATOR_HPP
00015
00016
00017 namespace lemur
00018 {
00019 namespace api
00020 {
00021
00022
00023
00024
00025
00027 class ScoreAccumulator {
00028 public:
00029 virtual ~ScoreAccumulator(){}
00030
00032 virtual void reset()=0;
00034 virtual bool findScore(int id, double &score)const =0;
00036 virtual void setScore(int id, double score)=0;
00038 virtual void incScore(int id, double score)=0;
00039
00041 virtual void startIteration()const =0;
00042 virtual bool hasMore() const = 0;
00043 virtual void nextScore(int &id, double &score) const =0;
00044
00045 };
00046 }
00047 }
00048
00049 namespace lemur
00050 {
00051 namespace retrieval
00052 {
00053
00054
00055
00056
00057
00059 class ArrayAccumulator : public lemur::api::ScoreAccumulator {
00060 public:
00061 ArrayAccumulator(int maxID);
00062
00063 virtual ~ArrayAccumulator() { delete [] acc; delete [] status;}
00064
00066 virtual void reset();
00067
00069 virtual bool findScore(int id, double &score) const ;
00070
00072 virtual void setScore(int id, double score) {
00073 acc[id-1] = score;
00074 status[id-1] =1;
00075 }
00076
00078 virtual void incScore(int id, double score) {
00079 acc[id-1] += score;
00080 status[id-1] =1;
00081 }
00082
00084 virtual void startIteration() const { p = 0; }
00085 bool hasMore()const ;
00086
00087 void nextScore(int &id, double &score)const ;
00088
00089 protected:
00090 mutable int p;
00091 int sz;
00092 double *acc;
00093 short *status;
00094 };
00095
00096
00097
00098
00099 inline ArrayAccumulator::ArrayAccumulator(int maxID) : sz(maxID)
00100 {
00101 acc = new double[maxID];
00102 status = new short[maxID];
00103 }
00104 }
00105 }
00106
00107
00108 #endif