107 |
107 |
108 // ---------------------------------------------------------------------------- |
108 // ---------------------------------------------------------------------------- |
109 // CPcsAlgorithm2FilterHelper::AddL |
109 // CPcsAlgorithm2FilterHelper::AddL |
110 // |
110 // |
111 // ---------------------------------------------------------------------------- |
111 // ---------------------------------------------------------------------------- |
112 void CPcsAlgorithm2FilterHelper::AddL(CPsData* psData, RPointerArray<TDesC>& aPatternSequence) |
112 void CPcsAlgorithm2FilterHelper::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 const TInt patternSequenceCount = aPatternSequence.Count(); |
130 { |
132 for (TInt i = 0; i < patternSequenceCount; i++) |
131 TInt index = FindSequence(aPatternSequence[i]); |
133 { |
|
134 TInt index = FindSequence(*aPatternSequence[i]); |
132 if (index == KErrNotFound) |
135 if (index == KErrNotFound) |
133 { |
136 { |
134 // sequence not found, add it to array |
137 // sequence not found, add it to array |
135 TPsPatternDetails* temp = new (ELeave) TPsPatternDetails; |
138 TPsPatternDetails* temp = new (ELeave) TPsPatternDetails; |
136 |
139 CleanupStack::PushL( temp ); |
137 TInt len = aPatternSequence[i]->Length(); |
140 |
138 temp->matchPattern = HBufC::NewL(len); |
141 temp->matchPattern = aPatternSequence[i]->AllocL(); |
139 temp->matchPattern->Des().Copy(*(aPatternSequence[i])); |
|
140 |
142 |
141 // First occurence should be -1 for alphabetical sort |
143 // First occurence should be -1 for alphabetical sort |
142 // and pool index will be 0 as only one pool will be created |
144 // and pool index will be 0 as only one pool will be created |
143 temp->firstOccurence = -1; |
145 temp->firstOccurence = -1; |
144 temp->poolIndex = 0; |
146 temp->poolIndex = 0; |
145 |
147 |
146 iMatchPatternDetails.Append(temp); |
148 iMatchPatternDetails.AppendL(temp); |
|
149 CleanupStack::Pop( temp ); |
147 } |
150 } |
148 } |
151 } |
149 } |
152 } |
150 else |
153 else |
151 { |
154 { |
152 // PatternBased sort |
155 // PatternBased sort |
153 TInt index = AddToPoolL(psData, aPatternSequence); |
156 TInt index = AddToPoolL(aPsData, aPatternSequence); |
154 |
157 |
155 // Increment the total count |
158 // Increment the total count |
156 iResultCount++; |
159 iResultCount++; |
157 |
|
158 } |
160 } |
159 } |
161 } |
160 |
162 |
161 // ---------------------------------------------------------------------------- |
163 // ---------------------------------------------------------------------------- |
162 // CPcsAlgorithm2FilterHelper::AddToPoolL |
164 // CPcsAlgorithm2FilterHelper::AddToPoolL |
163 // |
165 // |
164 // ---------------------------------------------------------------------------- |
166 // ---------------------------------------------------------------------------- |
165 |
167 |
166 TInt CPcsAlgorithm2FilterHelper::AddToPoolL(CPsData* psData, RPointerArray<TDesC>& aPatternSequence) |
168 TInt CPcsAlgorithm2FilterHelper::AddToPoolL(CPsData* aPsData, RPointerArray<TDesC>& aPatternSequence) |
167 { |
169 { |
168 |
170 |
169 // Sort the pattern sequence |
171 // Sort the pattern sequence |
170 TLinearOrder<TDesC> rule(CPcsAlgorithm2Utils::MyCompareC); |
172 TLinearOrder<TDesC> rule(CPcsAlgorithm2Utils::MyCompareC); |
171 aPatternSequence.Sort(rule); |
173 aPatternSequence.Sort(rule); |
177 TIdentityRelation<CPsData> identitySearchRule(CPsData::CompareById); |
179 TIdentityRelation<CPsData> identitySearchRule(CPsData::CompareById); |
178 |
180 |
179 TInt poolItemCount = -1; |
181 TInt poolItemCount = -1; |
180 TInt matchpatterpoolIndexToAppend = -1; |
182 TInt matchpatterpoolIndexToAppend = -1; |
181 |
183 |
182 for (TInt cnt = 0; cnt < aPatternSequence.Count(); cnt++) |
184 const TInt patternSequenceCount = aPatternSequence.Count(); |
|
185 for (TInt cnt = 0; cnt < patternSequenceCount; cnt++) |
183 { |
186 { |
184 |
187 |
185 // Create the pattern for aPatternSequence[cnt] in iMatchPatternDetails |
188 // Create the pattern for aPatternSequence[cnt] in iMatchPatternDetails |
186 // and return the index |
189 // and return the index |
187 TInt indexInMatchPatternDetails = CreateMatchPatternDetailsAndPoolsL(aPatternSequence[cnt]); |
190 TInt indexInMatchPatternDetails = CreateMatchPatternDetailsAndPoolsL(*aPatternSequence[cnt]); |
188 |
191 |
189 //Add the data to the pool the first pattern pool. |
192 //Add the data to the pool the first pattern pool. |
190 // The data should be added only once |
193 // The data should be added only once |
191 if (cnt == 0) |
194 if (cnt == 0) |
192 { |
195 { |
193 TInt poolIndex = iMatchPatternDetails[indexInMatchPatternDetails]->poolIndex; |
196 TInt poolIndex = iMatchPatternDetails[indexInMatchPatternDetails]->poolIndex; |
194 matchpatterpoolIndexToAppend = indexInMatchPatternDetails; |
197 matchpatterpoolIndexToAppend = indexInMatchPatternDetails; |
195 iMatchPatternPools[poolIndex]->InsertInOrderAllowRepeats(psData, psDataRule); |
198 iMatchPatternPools[poolIndex]->InsertInOrderAllowRepeats(aPsData, psDataRule); |
196 TInt findposition = iMatchPatternPools[poolIndex]->Find(psData, identitySearchRule); |
199 TInt findposition = iMatchPatternPools[poolIndex]->Find(aPsData, identitySearchRule); |
197 if (findposition != KErrNotFound) |
200 if (findposition != KErrNotFound) |
198 { |
201 { |
199 poolItemCount = findposition; |
202 poolItemCount = findposition; |
200 } |
203 } |
201 else |
204 else |
206 } |
209 } |
207 else if (cnt > 0) |
210 else if (cnt > 0) |
208 { |
211 { |
209 // Check if aPatternSequence[cnt] is listed in subpatterns of aPatternSequence[0] |
212 // Check if aPatternSequence[cnt] is listed in subpatterns of aPatternSequence[0] |
210 // 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] |
211 TInt subSeq = FindSubSequence(aPatternSequence[cnt], matchpatterpoolIndexToAppend); |
214 TInt subSeq = FindSubSequence(*aPatternSequence[cnt], matchpatterpoolIndexToAppend); |
212 if (subSeq == KErrNotFound) |
215 if (subSeq == KErrNotFound) |
213 { |
216 { |
214 //Create the subpattern and append it. |
217 //Create the subpattern and append it. |
215 TPsSubPattern* tempSubPattern = new (ELeave) TPsSubPattern; |
218 TPsSubPattern* tempSubPattern = new (ELeave) TPsSubPattern; |
216 tempSubPattern->matchPattern = HBufC::NewL(aPatternSequence[cnt]->Length()); |
219 tempSubPattern->matchPattern = HBufC::NewL(aPatternSequence[cnt]->Length()); |
228 // CPcsAlgorithm2FilterHelper::CreateMatchPatternDetailsAndPoolsL |
231 // CPcsAlgorithm2FilterHelper::CreateMatchPatternDetailsAndPoolsL |
229 // Creates the Matchpattern aSeq in iMatchPatternDetails. |
232 // Creates the Matchpattern aSeq in iMatchPatternDetails. |
230 // Returns the index of the sequence in iMatchPatternDetails |
233 // Returns the index of the sequence in iMatchPatternDetails |
231 // ---------------------------------------------------------------------------- |
234 // ---------------------------------------------------------------------------- |
232 |
235 |
233 TInt CPcsAlgorithm2FilterHelper::CreateMatchPatternDetailsAndPoolsL(TDesC* aSeq) |
236 TInt CPcsAlgorithm2FilterHelper::CreateMatchPatternDetailsAndPoolsL(const TDesC& aSeq) |
234 { |
237 { |
235 |
238 |
236 TInt indexInMatchPatternDetails = FindSequence(aSeq); |
239 TInt indexInMatchPatternDetails = FindSequence(aSeq); |
237 if (indexInMatchPatternDetails == KErrNotFound) |
240 if (indexInMatchPatternDetails == KErrNotFound) |
238 { |
241 { |
239 // sequence not found, add it to array |
242 // sequence not found, add it to array |
240 TPsPatternDetails* tempPatternDetailsInstance = new (ELeave) TPsPatternDetails; |
243 TPsPatternDetails* tempPatternDetailsInstance = new (ELeave) TPsPatternDetails; |
241 |
244 |
242 //TInt len = aPatternSequence[cnt]->Length(); |
245 //TInt len = aPatternSequence[cnt]->Length(); |
243 tempPatternDetailsInstance->matchPattern = HBufC::NewL(aSeq->Length()); |
246 tempPatternDetailsInstance->matchPattern = aSeq.Alloc(); |
244 tempPatternDetailsInstance->matchPattern->Des().Copy(*(aSeq)); |
|
245 tempPatternDetailsInstance->firstOccurence = -1; //RAVIKIRAN |
247 tempPatternDetailsInstance->firstOccurence = -1; //RAVIKIRAN |
246 |
248 |
247 // Pools doesn't exist for this sequence.. |
249 // Pools doesn't exist for this sequence.. |
248 RPointerArray<CPsData> *tempPsDataArray = new (ELeave) RPointerArray<CPsData> (); |
250 RPointerArray<CPsData> *tempPsDataArray = new (ELeave) RPointerArray<CPsData> (); |
249 |
251 |
280 iMatchPatternDetails.Sort(rule); |
282 iMatchPatternDetails.Sort(rule); |
281 |
283 |
282 if (iSortType == EAlphabetical) |
284 if (iSortType == EAlphabetical) |
283 { |
285 { |
284 // Return the results stored in single array |
286 // Return the results stored in single array |
285 for (TInt i = 0; i < iMatchPatternPools[0]->Count(); i++) |
287 const TInt cnt = iMatchPatternPools[0]->Count(); |
|
288 for (TInt i = 0; i < cnt; i++) |
286 { |
289 { |
287 aSearchResults.Append((*(iMatchPatternPools[0]))[i]); |
290 aSearchResults.Append((*(iMatchPatternPools[0]))[i]); |
288 } |
291 } |
289 |
292 |
290 // Clear the match pattern pool for the next data store |
293 // Clear the match pattern pool for the next data store |
291 iMatchPatternPools[0]->Reset(); |
294 iMatchPatternPools[0]->Reset(); |
292 } |
295 } |
293 else |
296 else |
294 { |
297 { |
295 TInt firstOccurenceTracker = 0; |
298 TInt firstOccurenceTracker = 0; |
296 for (TInt i = 0; i < iMatchPatternDetails.Count(); i++) |
299 const TInt matchPatternDetailsCount = iMatchPatternDetails.Count(); |
|
300 for (TInt i = 0; i < matchPatternDetailsCount; i++) |
297 { |
301 { |
298 // Get the mapping pool index for this sequence |
302 // Get the mapping pool index for this sequence |
299 TInt index = iMatchPatternDetails[i]->poolIndex; |
303 TInt index = iMatchPatternDetails[i]->poolIndex; |
300 TInt j = 0; |
304 TInt j = 0; |
301 for (; j < iMatchPatternPools[index]->Count(); j++) |
305 const TInt poolCount = iMatchPatternPools[index]->Count(); |
|
306 for (; j < poolCount; j++) |
302 { |
307 { |
303 aSearchResults.Append((*(iMatchPatternPools[index]))[j]); |
308 aSearchResults.Append((*(iMatchPatternPools[index]))[j]); |
304 } |
309 } |
305 |
310 |
306 // Check the sub patterns |
311 // Check the sub patterns |
307 for (TInt k = 0; k < iMatchPatternDetails[i]->subPatternArray.Count(); k++) |
312 const TInt subPatternArrayCount = iMatchPatternDetails[i]->subPatternArray.Count(); |
|
313 for (TInt k = 0; k < subPatternArrayCount; k++) |
308 { |
314 { |
309 HBufC* temporseq = iMatchPatternDetails[i]->subPatternArray[k]->matchPattern; |
315 HBufC* temporseq = iMatchPatternDetails[i]->subPatternArray[k]->matchPattern; |
310 TRAP_IGNORE( UpdateForSubSequencesL( *temporseq, |
316 TRAP_IGNORE( UpdateForSubSequencesL( *temporseq, |
311 firstOccurenceTracker + |
317 firstOccurenceTracker + |
312 iMatchPatternDetails[i]->subPatternArray[k]->firstOccurenceInThisPattern ) ); |
318 iMatchPatternDetails[i]->subPatternArray[k]->firstOccurenceInThisPattern ) ); |
349 // ---------------------------------------------------------------------------- |
356 // ---------------------------------------------------------------------------- |
350 // CPcsAlgorithm2FilterHelper::FindSequence |
357 // CPcsAlgorithm2FilterHelper::FindSequence |
351 // Searches for for aSeq in iMatchPatternDetails and returns index |
358 // Searches for for aSeq in iMatchPatternDetails and returns index |
352 // where input sequence is found. Returns -1 if not found |
359 // where input sequence is found. Returns -1 if not found |
353 // ---------------------------------------------------------------------------- |
360 // ---------------------------------------------------------------------------- |
354 TInt CPcsAlgorithm2FilterHelper::FindSequence(TDesC* aSeq) |
361 TInt CPcsAlgorithm2FilterHelper::FindSequence(const TDesC& aSeq) |
355 { |
362 { |
356 TBuf<50> seqBuf; |
|
357 seqBuf.Append(*aSeq); |
|
358 |
|
359 TInt j = 0; |
363 TInt j = 0; |
360 for (; j < iMatchPatternDetails.Count(); j++) |
364 const TInt matchPatternDetailsCount = iMatchPatternDetails.Count(); |
361 { |
365 for (; j < matchPatternDetailsCount; j++) |
362 TBuf<50> matchPatternBuf; |
366 { |
363 matchPatternBuf.Copy((iMatchPatternDetails[j]->matchPattern->Des())); |
367 const TDesC& matchPattern = *(iMatchPatternDetails[j]->matchPattern); |
364 if (seqBuf == matchPatternBuf) |
368 if ( CPcsAlgorithm2Utils::MyCompareC(aSeq, matchPattern) == 0 ) |
365 break; |
369 break; |
366 } |
370 } |
367 |
371 |
368 if (j == iMatchPatternDetails.Count()) |
372 if (j == iMatchPatternDetails.Count()) |
369 return KErrNotFound; |
373 return KErrNotFound; |
375 // CPcsAlgorithm2FilterHelper::FindSubSequence |
379 // CPcsAlgorithm2FilterHelper::FindSubSequence |
376 // Searches for for seq in subpatterns of iMatchPatternDetails[aPatternIndex] |
380 // Searches for for seq in subpatterns of iMatchPatternDetails[aPatternIndex] |
377 // and returns index where input sequence is found. |
381 // and returns index where input sequence is found. |
378 // Returns -1 if not found |
382 // Returns -1 if not found |
379 // ---------------------------------------------------------------------------- |
383 // ---------------------------------------------------------------------------- |
380 TInt CPcsAlgorithm2FilterHelper::FindSubSequence(TDesC* aSeq, TInt aPatternIndex) |
384 TInt CPcsAlgorithm2FilterHelper::FindSubSequence(const TDesC& aSeq, TInt aPatternIndex) |
381 { |
385 { |
382 TBuf<50> seqBuf; |
|
383 seqBuf.Append(*aSeq); |
|
384 |
|
385 TInt j = 0; |
386 TInt j = 0; |
386 for (; j < iMatchPatternDetails[aPatternIndex]->subPatternArray.Count(); j++) |
387 const TInt subPatternArraycount = iMatchPatternDetails[aPatternIndex]->subPatternArray.Count(); |
387 { |
388 for (; j < subPatternArraycount; j++) |
388 TBuf<50> matchPatternBuf; |
389 { |
389 matchPatternBuf.Copy((iMatchPatternDetails[aPatternIndex]->subPatternArray[j]->matchPattern->Des())); |
390 const TDesC& matchPattern = *(iMatchPatternDetails[aPatternIndex]->subPatternArray[j]->matchPattern); |
390 if (seqBuf == matchPatternBuf) |
391 if ( CPcsAlgorithm2Utils::MyCompareC(aSeq, matchPattern) == 0 ) |
391 break; |
392 break; |
392 } |
393 } |
393 |
394 |
394 if (j == iMatchPatternDetails[aPatternIndex]->subPatternArray.Count()) |
395 if (j == iMatchPatternDetails[aPatternIndex]->subPatternArray.Count()) |
395 { |
396 { |
408 // |
409 // |
409 // For ex: if aSeq = "ABC" and aFirstOccrVal= 2, |
410 // For ex: if aSeq = "ABC" and aFirstOccrVal= 2, |
410 // then, firstOccurence of all substring sequences ("A", "AB", "ABC") |
411 // then, firstOccurence of all substring sequences ("A", "AB", "ABC") |
411 // in iMatchPatternDetails will be set to 2 |
412 // in iMatchPatternDetails will be set to 2 |
412 // ---------------------------------------------------------------------------- |
413 // ---------------------------------------------------------------------------- |
413 void CPcsAlgorithm2FilterHelper::UpdateForSubSequencesL(TDesC& aSeq, TInt aFirstOccrVal) |
414 void CPcsAlgorithm2FilterHelper::UpdateForSubSequencesL(const TDesC& aSeq, TInt aFirstOccrVal) |
414 { |
415 { |
415 HBufC* tempSequence = HBufC::NewL(aSeq.Length() + 1); |
416 TPtrC tempSequence; |
416 for (TInt i = 0; i < aSeq.Length(); i++) |
417 for ( TInt i = 1; i <= aSeq.Length(); i++ ) |
417 { |
418 { |
418 // Get the next substring in tempSequence |
419 // Get the next substring in tempSequence |
419 tempSequence->Des().Append(aSeq[i]); |
420 tempSequence.Set( aSeq.Left(i) ); |
420 |
421 |
421 // Find if this sequence exist in iMatchPatternDetails |
422 // Find if this sequence exist in iMatchPatternDetails |
422 TInt patternIndex = FindSequence(tempSequence); |
423 TInt patternIndex = FindSequence(tempSequence); |
423 |
424 |
424 //If the sequence exits and firstOccurence == -1, then set it to aFirstOccrVal |
425 //If the sequence exits and firstOccurence == -1, then set it to aFirstOccrVal |