summaryrefslogtreecommitdiff
path: root/inputmethods
authorerik <erik>2007-01-19 01:12:38 (UTC)
committer erik <erik>2007-01-19 01:12:38 (UTC)
commit1ab92f1d2b346de7da8ca5c3aaa6bc75b43981e7 (patch) (unidiff)
treeaf4a12bc46e25853386dc53868b869e1bf05d863 /inputmethods
parent2b45dc71e79a3eb7d4e8553273c9bc4f4282d50a (diff)
downloadopie-1ab92f1d2b346de7da8ca5c3aaa6bc75b43981e7.zip
opie-1ab92f1d2b346de7da8ca5c3aaa6bc75b43981e7.tar.gz
opie-1ab92f1d2b346de7da8ca5c3aaa6bc75b43981e7.tar.bz2
Every single file in this commit had a memory leak where a resource is
allocated in the constructor but not de-allocated in the destructor. This commit fixes that.
Diffstat (limited to 'inputmethods') (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/dasher/PPMLanguageModel.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/inputmethods/dasher/PPMLanguageModel.cpp b/inputmethods/dasher/PPMLanguageModel.cpp
index 137b07f..d767d16 100644
--- a/inputmethods/dasher/PPMLanguageModel.cpp
+++ b/inputmethods/dasher/PPMLanguageModel.cpp
@@ -14,105 +14,106 @@ using namespace std;
14 14
15// static TCHAR debug[256]; 15// static TCHAR debug[256];
16typedef unsigned long ulong; 16typedef unsigned long ulong;
17 17
18//////////////////////////////////////////////////////////////////////// 18////////////////////////////////////////////////////////////////////////
19/// PPMnode definitions 19/// PPMnode definitions
20//////////////////////////////////////////////////////////////////////// 20////////////////////////////////////////////////////////////////////////
21 21
22CPPMLanguageModel::CPPMnode *CPPMLanguageModel::CPPMnode::find_symbol(int sym) 22CPPMLanguageModel::CPPMnode *CPPMLanguageModel::CPPMnode::find_symbol(int sym)
23// see if symbol is a child of node 23// see if symbol is a child of node
24{ 24{
25 // printf("finding symbol %d at node %d\n",sym,node->id); 25 // printf("finding symbol %d at node %d\n",sym,node->id);
26 CPPMnode *found=child; 26 CPPMnode *found=child;
27 while (found) { 27 while (found) {
28 if (found->symbol==sym) 28 if (found->symbol==sym)
29 return found; 29 return found;
30 found=found->next; 30 found=found->next;
31 } 31 }
32 return 0; 32 return 0;
33} 33}
34 34
35 35
36CPPMLanguageModel::CPPMnode * CPPMLanguageModel::CPPMnode::add_symbol_to_node(int sym,int *update) 36CPPMLanguageModel::CPPMnode * CPPMLanguageModel::CPPMnode::add_symbol_to_node(int sym,int *update)
37{ 37{
38 CPPMnode *born,*search; 38 CPPMnode *born,*search;
39 search=find_symbol(sym); 39 search=find_symbol(sym);
40 if (!search) { 40 if (!search) {
41 born = new CPPMnode(sym); 41 born = new CPPMnode(sym);
42 born->next=child; 42 born->next=child;
43 child=born; 43 child=born;
44 // node->count=1; 44 // node->count=1;
45 return born; 45 return born;
46 } else { 46 } else {
47 if (*update) { // perform update exclusions 47 if (*update) { // perform update exclusions
48 search->count++; 48 search->count++;
49 *update=0; 49 *update=0;
50 } 50 }
51 return search; 51 return search;
52 } 52 }
53 53
54} 54}
55 55
56 56
57///////////////////////////////////////////////////////////////////// 57/////////////////////////////////////////////////////////////////////
58// CPPMLanguageModel defs 58// CPPMLanguageModel defs
59///////////////////////////////////////////////////////////////////// 59/////////////////////////////////////////////////////////////////////
60 60
61CPPMLanguageModel::CPPMLanguageModel(CAlphabet *_alphabet,int _normalization) 61CPPMLanguageModel::CPPMLanguageModel(CAlphabet *_alphabet,int _normalization)
62 : CLanguageModel(_alphabet,_normalization) 62 : CLanguageModel(_alphabet,_normalization), root(0), m_rootcontext(0)
63{ 63{
64 root=new CPPMnode(-1); 64 root=new CPPMnode(-1);
65 m_rootcontext=new CPPMContext(root,0); 65 m_rootcontext=new CPPMContext(root,0);
66} 66}
67 67
68 68
69CPPMLanguageModel::~CPPMLanguageModel() 69CPPMLanguageModel::~CPPMLanguageModel()
70{ 70{
71 delete m_rootcontext;
71 delete root; 72 delete root;
72} 73}
73 74
74 75
75bool CPPMLanguageModel::GetProbs(CContext *context,vector<unsigned int> &probs,double ) 76bool CPPMLanguageModel::GetProbs(CContext *context,vector<unsigned int> &probs,double )
76 // get the probability distribution at the context 77 // get the probability distribution at the context
77{ 78{
78 // seems like we have to have this hack for VC++ 79 // seems like we have to have this hack for VC++
79 CPPMContext *ppmcontext=static_cast<CPPMContext *> (context); 80 CPPMContext *ppmcontext=static_cast<CPPMContext *> (context);
80 81
81 82
82 int modelchars=GetNumberModelChars(); 83 int modelchars=GetNumberModelChars();
83 int norm=CLanguageModel::normalization(); 84 int norm=CLanguageModel::normalization();
84 probs.resize(modelchars); 85 probs.resize(modelchars);
85 CPPMnode *temp,*s; 86 CPPMnode *temp,*s;
86 int loop,total; 87 int loop,total;
87 int sym; 88 int sym;
88 // ulong spent=0; 89 // ulong spent=0;
89 ulong size_of_slice; 90 ulong size_of_slice;
90 bool *exclusions=new bool [modelchars]; 91 bool *exclusions=new bool [modelchars];
91 ulong uniform=modelchars; 92 ulong uniform=modelchars;
92 ulong tospend=norm-uniform; 93 ulong tospend=norm-uniform;
93 temp=ppmcontext->head; 94 temp=ppmcontext->head;
94 for (loop=0; loop <modelchars; loop++) { /* set up the exclusions array */ 95 for (loop=0; loop <modelchars; loop++) { /* set up the exclusions array */
95 probs[loop]=0; 96 probs[loop]=0;
96 exclusions[loop]=0; 97 exclusions[loop]=0;
97 } 98 }
98 while (temp!=0) { 99 while (temp!=0) {
99 //Usprintf(debug,TEXT("tospend %u\n"),tospend); 100 //Usprintf(debug,TEXT("tospend %u\n"),tospend);
100 //DebugOutput(TEXT("round\n")); 101 //DebugOutput(TEXT("round\n"));
101 total=0; 102 total=0;
102 s=temp->child; 103 s=temp->child;
103 while (s) { 104 while (s) {
104 sym=s->symbol; 105 sym=s->symbol;
105 if (!exclusions[s->symbol]) 106 if (!exclusions[s->symbol])
106 total=total+s->count; 107 total=total+s->count;
107 s=s->next; 108 s=s->next;
108 } 109 }
109 if (total) { 110 if (total) {
110 //Usprintf(debug,TEXT"escape %u\n"),tospend* 111 //Usprintf(debug,TEXT"escape %u\n"),tospend*
111 size_of_slice=tospend; 112 size_of_slice=tospend;
112 s=temp->child; 113 s=temp->child;
113 while (s) { 114 while (s) {
114 if (!exclusions[s->symbol]) { 115 if (!exclusions[s->symbol]) {
115 exclusions[s->symbol]=1; 116 exclusions[s->symbol]=1;
116 ulong p=size_of_slice*(2*s->count-1)/2/ulong(total); 117 ulong p=size_of_slice*(2*s->count-1)/2/ulong(total);
117 probs[s->symbol]+=p; 118 probs[s->symbol]+=p;
118 tospend-=p; 119 tospend-=p;