File: CDocumentFrequencyList.cc

package info (click to toggle)
gnuift 0.1.14%2Bds-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 5,632 kB
  • ctags: 2,973
  • sloc: cpp: 15,867; sh: 8,281; ansic: 1,812; perl: 1,007; php: 651; makefile: 483; lisp: 344
file content (147 lines) | stat: -rw-r--r-- 3,450 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/***************************************
*
* CDocumentFrequencyList
*
****************************************
*
* modification history:
*
* HM 090399 created the documentation
* WM 10  98 created the file
****************************************
*
* compiler defines used:
*
*
****************************************/
#include "libGIFTAcInvertedFile/include/CDocumentFrequencyList.h"
#include <unistd.h> // debugging

#include "libMRML/include/CMutex.h"
extern CMutex* gMutex;

#ifdef __CDFL_MEM_DEBUG__
int gSize=0;
int gInSize=0;
#endif
/***************************************
*
* writeBinary
*
****************************************
*
* modification history
*
* 
*
****************************************/
CDocumentFrequencyList::CDocumentFrequencyList(size_t inSize):
#ifdef  _CDocumentFrequencyListIsArray
  mContent(new CDocumentFrequencyElement[inSize])
#else
#ifdef  _CDocumentFrequencyListIsVector
  vector<CDocumentFrequencyElement>(inSize)
#else
//otherwhise ignore the parameter
  list<CDocumentFrequencyElement>()
#endif
#endif 
{
  mSize=inSize;
#ifdef  _CDocumentFrequencyListIsArray
  mEnd=mContent+inSize;
#endif
#ifdef __CDFL_MEM_DEBUG__
  gSize+=size();
  gInSize+=inSize;
#endif
};
CDocumentFrequencyList::CDocumentFrequencyList():
#ifdef  _CDocumentFrequencyListIsVector
  vector<CDocumentFrequencyElement>()
#else
#ifdef  _CDocumentFrequencyListIsList
  //otherwhise ignore the parameter
  list<CDocumentFrequencyElement>()
#endif
#endif 
#ifdef  _CDocumentFrequencyListIsArray
  mContent(new CDocumentFrequencyElement[1])// will this work?
#endif
{
#ifdef  _CDocumentFrequencyListIsArray
  mSize=0;
  mEnd=mContent;
#endif
#ifdef __CDFL_MEM_DEBUG__
  gSize+=size();
  gInSize+=0;
#endif
};
CDocumentFrequencyList::~CDocumentFrequencyList(){
#ifdef  _CDocumentFrequencyListIsArray
  delete[] mContent;
#endif
#ifdef __CDFL_MEM_DEBUG__
  gSize-=size();
  gInSize-=mSize;
  cout << "[S" << gSize << "," << gInSize << "]" << flush;
#endif
}
bool CDocumentFrequencyList::writeBinary(ostream& outStream)const{
  bool lRetVal=true;

#ifdef _CDocumentFrequencyListIsArray
  outStream.write((char*)mContent,size()*sizeof(CDocumentFrequencyElement));
#else
  for(const_iterator i=begin();
      i!=end();
      i++){
    lRetVal=
      lRetVal && (*i).writeBinary(outStream);
  }
#endif
  return lRetVal;
};
bool CDocumentFrequencyList::readBinary(istream& inStream){
#ifdef _CDocumentFrequencyListIsList
  for(unsigned int i=0;
      i<mSize && inStream;
      i++){
    //neat: construct CDocumentFrequencyElement
    //      directly from file
    push_back(CDocumentFrequencyElement(inStream));
  }
#else
  if(inStream){
    //gMutex->lock();
    //    cout << "|[" << getpid() << flush;
    inStream.read((char*)begin(),size()*sizeof(CDocumentFrequencyElement));
    //cout << "]" << flush; <gMutex->unlock();
  }
#endif

  return bool(inStream);
};
#ifdef _CDocumentFrequencyListIsArray
CDocumentFrequencyList::iterator CDocumentFrequencyList::begin(){
  return mContent;
}
CDocumentFrequencyList::iterator CDocumentFrequencyList::end(){
  return mEnd;
}
CDocumentFrequencyList::const_iterator CDocumentFrequencyList::begin()const{
  return mContent;
}
CDocumentFrequencyList::const_iterator CDocumentFrequencyList::end()const{
  return mEnd;
}
size_t CDocumentFrequencyList::size()const{
  return mSize;
}

void CDocumentFrequencyList::setEnd(CDocumentFrequencyElement* inEnd){
  mEnd=inEnd;
  mSize=mEnd-mContent;
}
#endif