19 // INCLUDES |
19 // INCLUDES |
20 #include "CPcsAlgorithm1FilterHelper.h" |
20 #include "CPcsAlgorithm1FilterHelper.h" |
21 #include "CPcsDebug.h" |
21 #include "CPcsDebug.h" |
22 |
22 |
23 // Compare functions |
23 // Compare functions |
24 TBool ComparePsPattern ( const TPsPatternDetails& aFirst, const TPsPatternDetails& aSecond ) |
24 TInt ComparePsPattern ( const TPsPatternDetails& aFirst, const TPsPatternDetails& aSecond ) |
25 { |
25 { |
26 return (CPcsAlgorithm1Utils::MyCompareC(*(aFirst.matchPattern), *(aSecond.matchPattern))); |
26 return (CPcsAlgorithm1Utils::MyCompareC(*(aFirst.matchPattern), *(aSecond.matchPattern))); |
27 } |
27 } |
28 |
28 |
29 // ============================== MEMBER FUNCTIONS ============================ |
29 // ============================== MEMBER FUNCTIONS ============================ |
107 |
107 |
108 // ---------------------------------------------------------------------------- |
108 // ---------------------------------------------------------------------------- |
109 // CPcsAlgorithm1FilterHelper::AddL |
109 // CPcsAlgorithm1FilterHelper::AddL |
110 // |
110 // |
111 // ---------------------------------------------------------------------------- |
111 // ---------------------------------------------------------------------------- |
112 void CPcsAlgorithm1FilterHelper::AddL(CPsData* psData, RPointerArray<TDesC>& aPatternSequence) |
112 void CPcsAlgorithm1FilterHelper::AddL(CPsData* aPsData, RPointerArray<TDesC>& aPatternSequence) |
113 { |
113 { |
114 if(iSortType == EAlphabetical) |
114 if(iSortType == EAlphabetical) |
115 { |
115 { |
116 // Create pool if not already present |
116 // Create pool if not already present |
117 if(iMatchPatternPools.Count() == 0 ) |
117 if(iMatchPatternPools.Count() == 0 ) |
118 { |
118 { |
119 RPointerArray<CPsData> *tempPsDataArray = new (ELeave) RPointerArray<CPsData> (); |
119 RPointerArray<CPsData> *tempPsDataArray = new (ELeave) RPointerArray<CPsData> (); |
120 iMatchPatternPools.Append(tempPsDataArray); |
120 CleanupStack::PushL( tempPsDataArray ); |
|
121 iMatchPatternPools.AppendL(tempPsDataArray); |
|
122 CleanupStack::Pop( tempPsDataArray ); |
121 } |
123 } |
122 // Add result to the result set |
124 // Add result to the result set |
123 iMatchPatternPools[0]->Append(psData); |
125 iMatchPatternPools[0]->AppendL(aPsData); |
124 |
126 |
125 // Update the count |
127 // Update the count |
126 iResultCount++; |
128 iResultCount++; |
127 |
129 |
128 // Update sequence list |
130 // Update sequence list |
129 for(TInt i = 0; i < aPatternSequence.Count(); i++) |
131 for(TInt i = 0; i < aPatternSequence.Count(); i++) |
130 { |
132 { |
131 TInt index = FindSequence(aPatternSequence[i]); |
133 TInt index = FindSequence(*aPatternSequence[i]); |
132 if ( index == KErrNotFound ) |
134 if ( index == KErrNotFound ) |
133 { |
135 { |
134 // sequence not found, add it to array |
136 // sequence not found, add it to array |
135 TPsPatternDetails* temp = new ( ELeave ) TPsPatternDetails; |
137 TPsPatternDetails* temp = new ( ELeave ) TPsPatternDetails; |
|
138 CleanupStack::PushL( temp ); |
136 |
139 |
137 TInt len = aPatternSequence[i]->Length(); |
140 temp->matchPattern = aPatternSequence[i]->AllocL(); |
138 temp->matchPattern = HBufC::NewL(len); |
|
139 temp->matchPattern->Des().Copy(*(aPatternSequence[i])); |
|
140 |
141 |
141 // First occurence should be -1 for alphabetical sort |
142 // First occurence should be -1 for alphabetical sort |
142 // and pool index will be 0 as only one pool will be created |
143 // and pool index will be 0 as only one pool will be created |
143 temp->firstOccurence = -1; |
144 temp->firstOccurence = -1; |
144 temp->poolIndex = 0; |
145 temp->poolIndex = 0; |
145 |
146 |
146 iMatchPatternDetails.Append(temp); |
147 iMatchPatternDetails.AppendL(temp); |
|
148 CleanupStack::Pop( temp ); |
147 } |
149 } |
148 } |
150 } |
149 } |
151 } |
150 else |
152 else |
151 { |
153 { |
152 // PatternBased sort |
154 // PatternBased sort |
153 TInt index = AddToPoolL(psData, aPatternSequence); |
155 TInt index = AddToPoolL(aPsData, aPatternSequence); |
154 |
156 |
155 // Increment the total count |
157 // Increment the total count |
156 iResultCount++; |
158 iResultCount++; |
157 |
|
158 } |
159 } |
159 } |
160 } |
160 |
161 |
161 // ---------------------------------------------------------------------------- |
162 // ---------------------------------------------------------------------------- |
162 // CPcsAlgorithm1FilterHelper::AddToPoolL |
163 // CPcsAlgorithm1FilterHelper::AddToPoolL |
184 for(TInt cnt=0; cnt <aPatternSequence.Count(); cnt++ ) |
185 for(TInt cnt=0; cnt <aPatternSequence.Count(); cnt++ ) |
185 { |
186 { |
186 |
187 |
187 // Create the pattern for aPatternSequence[cnt] in iMatchPatternDetails |
188 // Create the pattern for aPatternSequence[cnt] in iMatchPatternDetails |
188 // and return the index |
189 // and return the index |
189 TInt indexInMatchPatternDetails = CreateMatchPatternDetailsAndPoolsL(aPatternSequence[cnt]); |
190 TInt indexInMatchPatternDetails = CreateMatchPatternDetailsAndPoolsL(*aPatternSequence[cnt]); |
190 |
191 |
191 //Add the data to the pool the first pattern pool. |
192 //Add the data to the pool the first pattern pool. |
192 // The data should be added only once |
193 // The data should be added only once |
193 if(cnt == 0) |
194 if(cnt == 0) |
194 { |
195 { |
201 poolItemCount = findposition; |
202 poolItemCount = findposition; |
202 } |
203 } |
203 else |
204 else |
204 { |
205 { |
205 poolItemCount = -1; |
206 poolItemCount = -1; |
206 } |
207 } |
207 |
208 |
208 } |
209 } |
209 else if(cnt > 0) |
210 else if(cnt > 0) |
210 { |
211 { |
211 // Check if aPatternSequence[cnt] is listed in subpatterns of aPatternSequence[0] |
212 // Check if aPatternSequence[cnt] is listed in subpatterns of aPatternSequence[0] |
212 // If not, then create a sub pattern and apped it to iMatchPatternDetails for aPatternSequence[0] |
213 // If not, then create a sub pattern and apped it to iMatchPatternDetails for aPatternSequence[0] |
213 TInt subSeq = FindSubSequence(aPatternSequence[cnt],matchpatterpoolIndexToAppend); |
214 TInt subSeq = FindSubSequence(*aPatternSequence[cnt], matchpatterpoolIndexToAppend); |
214 if(subSeq == KErrNotFound ) |
215 if(subSeq == KErrNotFound ) |
215 { |
216 { |
216 |
217 |
217 //Create the subpattern and append it. |
218 //Create the subpattern and append it. |
218 TPsSubPattern* tempSubPattern = new ( ELeave ) TPsSubPattern; |
219 TPsSubPattern* tempSubPattern = new ( ELeave ) TPsSubPattern; |
233 // CPcsAlgorithm1FilterHelper::CreateMatchPatternDetailsAndPoolsL |
234 // CPcsAlgorithm1FilterHelper::CreateMatchPatternDetailsAndPoolsL |
234 // Creates the Matchpattern aSeq in iMatchPatternDetails. |
235 // Creates the Matchpattern aSeq in iMatchPatternDetails. |
235 // Returns the index of the sequence in iMatchPatternDetails |
236 // Returns the index of the sequence in iMatchPatternDetails |
236 // ---------------------------------------------------------------------------- |
237 // ---------------------------------------------------------------------------- |
237 |
238 |
238 TInt CPcsAlgorithm1FilterHelper::CreateMatchPatternDetailsAndPoolsL(TDesC* aSeq) |
239 TInt CPcsAlgorithm1FilterHelper::CreateMatchPatternDetailsAndPoolsL(const TDesC& aSeq) |
239 { |
240 { |
240 |
241 |
241 TInt indexInMatchPatternDetails = FindSequence(aSeq); |
242 TInt indexInMatchPatternDetails = FindSequence(aSeq); |
242 if ( indexInMatchPatternDetails == KErrNotFound ) |
243 if ( indexInMatchPatternDetails == KErrNotFound ) |
243 { |
244 { |
244 // sequence not found, add it to array |
245 // sequence not found, add it to array |
245 TPsPatternDetails* tempPatternDetailsInstance = new ( ELeave ) TPsPatternDetails; |
246 TPsPatternDetails* tempPatternDetailsInstance = new ( ELeave ) TPsPatternDetails; |
246 |
247 |
247 //TInt len = aPatternSequence[cnt]->Length(); |
248 //TInt len = aPatternSequence[cnt]->Length(); |
248 tempPatternDetailsInstance->matchPattern = HBufC::NewL(aSeq->Length()); |
249 tempPatternDetailsInstance->matchPattern = aSeq.AllocL(); |
249 tempPatternDetailsInstance->matchPattern->Des().Copy(*(aSeq)); |
|
250 tempPatternDetailsInstance->firstOccurence = -1; //RAVIKIRAN |
250 tempPatternDetailsInstance->firstOccurence = -1; //RAVIKIRAN |
251 |
251 |
252 // Pools doesn't exist for this sequence.. |
252 // Pools doesn't exist for this sequence.. |
253 RPointerArray<CPsData> *tempPsDataArray = new (ELeave) RPointerArray<CPsData> (); |
253 RPointerArray<CPsData> *tempPsDataArray = new (ELeave) RPointerArray<CPsData> (); |
254 |
254 |
351 // ---------------------------------------------------------------------------- |
351 // ---------------------------------------------------------------------------- |
352 // CPcsAlgorithm1FilterHelper::FindSequence |
352 // CPcsAlgorithm1FilterHelper::FindSequence |
353 // Searches for for aSeq in iMatchPatternDetails and returns index |
353 // Searches for for aSeq in iMatchPatternDetails and returns index |
354 // where input sequence is found. Returns -1 if not found |
354 // where input sequence is found. Returns -1 if not found |
355 // ---------------------------------------------------------------------------- |
355 // ---------------------------------------------------------------------------- |
356 TInt CPcsAlgorithm1FilterHelper::FindSequence(TDesC* aSeq) |
356 TInt CPcsAlgorithm1FilterHelper::FindSequence(const TDesC& aSeq) |
357 { |
357 { |
358 TBuf<KPsQueryMaxLen> seqBuf; |
|
359 seqBuf.Append(*aSeq); |
|
360 |
|
361 TInt j = 0; |
358 TInt j = 0; |
362 for( ; j < iMatchPatternDetails.Count(); j++) |
359 for( ; j < iMatchPatternDetails.Count(); j++) |
363 { |
360 { |
364 TBuf<KPsQueryMaxLen> matchPatternBuf; |
361 const TDesC& matchPattern = *(iMatchPatternDetails[j]->matchPattern); |
365 matchPatternBuf.Copy((iMatchPatternDetails[j]->matchPattern->Des())); |
362 if ( CPcsAlgorithm1Utils::MyCompareC(aSeq, matchPattern) == 0 ) |
366 if ( CPcsAlgorithm1Utils::MyCompareC(seqBuf, matchPatternBuf) == 0 ) |
|
367 break; |
363 break; |
368 } |
364 } |
369 |
365 |
370 if( j == iMatchPatternDetails.Count()) |
366 if( j == iMatchPatternDetails.Count()) |
371 return KErrNotFound; |
367 return KErrNotFound; |
377 // CPcsAlgorithm1FilterHelper::FindSubSequence |
373 // CPcsAlgorithm1FilterHelper::FindSubSequence |
378 // Searches for for seq in subpatterns of iMatchPatternDetails[aPatternIndex] |
374 // Searches for for seq in subpatterns of iMatchPatternDetails[aPatternIndex] |
379 // and returns index where input sequence is found. |
375 // and returns index where input sequence is found. |
380 // Returns -1 if not found |
376 // Returns -1 if not found |
381 // ---------------------------------------------------------------------------- |
377 // ---------------------------------------------------------------------------- |
382 TInt CPcsAlgorithm1FilterHelper::FindSubSequence(TDesC* aSeq,TInt aPatternIndex) |
378 TInt CPcsAlgorithm1FilterHelper::FindSubSequence(const TDesC& aSeq,TInt aPatternIndex) |
383 { |
379 { |
384 TBuf<KPsQueryMaxLen> seqBuf; |
|
385 seqBuf.Append(*aSeq); |
|
386 |
|
387 TInt j = 0; |
380 TInt j = 0; |
388 for( ; j < iMatchPatternDetails[aPatternIndex]->subPatternArray.Count(); j++) |
381 for( ; j < iMatchPatternDetails[aPatternIndex]->subPatternArray.Count(); j++) |
389 { |
382 { |
390 TBuf<KPsQueryMaxLen> matchPatternBuf; |
383 const TDesC& matchPattern = *(iMatchPatternDetails[aPatternIndex]->subPatternArray[j]->matchPattern); |
391 matchPatternBuf.Copy((iMatchPatternDetails[aPatternIndex]->subPatternArray[j]->matchPattern->Des())); |
384 if ( CPcsAlgorithm1Utils::MyCompareC(aSeq, matchPattern) == 0 ) |
392 if ( CPcsAlgorithm1Utils::MyCompareC(seqBuf, matchPatternBuf) == 0 ) |
|
393 break; |
385 break; |
394 } |
386 } |
395 |
387 |
396 if( j == iMatchPatternDetails[aPatternIndex]->subPatternArray.Count()) |
388 if( j == iMatchPatternDetails[aPatternIndex]->subPatternArray.Count()) |
397 return KErrNotFound; |
389 return KErrNotFound; |
406 // |
398 // |
407 // For ex: if aSeq = "ABC" and aFirstOccrVal= 2, |
399 // For ex: if aSeq = "ABC" and aFirstOccrVal= 2, |
408 // then, firstOccurence of all substring sequences ("A", "AB", "ABC") |
400 // then, firstOccurence of all substring sequences ("A", "AB", "ABC") |
409 // in iMatchPatternDetails will be set to 2 |
401 // in iMatchPatternDetails will be set to 2 |
410 // ---------------------------------------------------------------------------- |
402 // ---------------------------------------------------------------------------- |
411 void CPcsAlgorithm1FilterHelper::UpdateForSubSequencesL(TDesC& aSeq,TInt aFirstOccrVal) |
403 void CPcsAlgorithm1FilterHelper::UpdateForSubSequencesL(const TDesC& aSeq,TInt aFirstOccrVal) |
412 { |
404 { |
413 HBufC* tempSequence = HBufC::NewL(aSeq.Length() + 1); |
405 TPtrC tempSequence; |
414 for ( TInt i =0; i<aSeq.Length(); i++ ) |
406 for ( TInt i = 1; i <= aSeq.Length(); i++ ) |
415 { |
407 { |
416 // Get the next substring in tempSequence |
408 // Get the next substring in tempSequence |
417 tempSequence->Des().Append(aSeq[i]); |
409 tempSequence.Set( aSeq.Left(i) ); |
418 |
410 |
419 // Find if this sequence exist in iMatchPatternDetails |
411 // Find if this sequence exist in iMatchPatternDetails |
420 TInt patternIndex = FindSequence(tempSequence); |
412 TInt patternIndex = FindSequence(tempSequence); |
421 |
413 |
422 //If the sequence exits and firstOccurence == -1, then set it to aFirstOccrVal |
414 //If the sequence exits and firstOccurence == -1, then set it to aFirstOccrVal |
423 if((patternIndex != KErrNotFound) && (iMatchPatternDetails[patternIndex]->firstOccurence == -1)) |
415 if((patternIndex != KErrNotFound) && (iMatchPatternDetails[patternIndex]->firstOccurence == -1)) |
424 { |
416 { |
425 iMatchPatternDetails[patternIndex]->firstOccurence = aFirstOccrVal; |
417 iMatchPatternDetails[patternIndex]->firstOccurence = aFirstOccrVal; |
426 } |
418 } |
427 |
419 |
428 } |
420 } |
429 delete tempSequence; |
|
430 tempSequence = NULL; |
|
431 |
|
432 return; |
|
433 |
|
434 } |
421 } |
435 // END OF FILE |
422 // END OF FILE |
436 |
423 |