|
1 /* |
|
2 * Copyright (c) 2005,2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Optimizer module for ChspsDomStringPool. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef HSPS_DOM_STRING_POOL_OPTIMIZER_H |
|
19 #define HSPS_DOM_STRING_POOL_OPTIMIZER_H |
|
20 |
|
21 // INCLUDES |
|
22 #include <e32base.h> |
|
23 |
|
24 // CLASS DECLARATION |
|
25 |
|
26 /** |
|
27 * @ingroup group_hspsdom |
|
28 * Optimizer module entry for ChspsDomStringPool. |
|
29 * |
|
30 * @lib hspsdomdocument.lib |
|
31 * @since Series 60 5.2 |
|
32 */ |
|
33 class ThspsDomStringPoolOptimizerEntry |
|
34 { |
|
35 public: // Construction. |
|
36 /** |
|
37 * Constructor. |
|
38 * |
|
39 * @param aIndex Index. |
|
40 * @param aString String. |
|
41 */ |
|
42 ThspsDomStringPoolOptimizerEntry( TInt aIndex, const TDesC8& aString ); |
|
43 |
|
44 public: // Data. |
|
45 /** |
|
46 * Index of string in actual string pool. |
|
47 */ |
|
48 TInt iIndex; |
|
49 |
|
50 /** |
|
51 * Reference to string in string pool. |
|
52 */ |
|
53 const TDesC8& iString; |
|
54 }; |
|
55 |
|
56 /** |
|
57 * @ingroup group_hspsdom |
|
58 * Optimizer module for ChspsDomStringPool. |
|
59 * |
|
60 * @lib hspsdomdocument.lib |
|
61 * @since Series 60 5.2 |
|
62 */ |
|
63 class ThspsDomStringPoolOptimizer |
|
64 { |
|
65 public: |
|
66 /** |
|
67 * Add entry to optimizer list. |
|
68 * |
|
69 * @param aEntry Entry to be added. |
|
70 */ |
|
71 void AddEntryL( ThspsDomStringPoolOptimizerEntry& aEntry ); |
|
72 |
|
73 /** |
|
74 * Get index for string. |
|
75 * |
|
76 * @param aString Reference to given string. |
|
77 * @return TInt Index to actual string pool for string if found. |
|
78 * If string is not found will return KErrNotFound. |
|
79 */ |
|
80 TInt GetIndex( const TDesC8& aString ); |
|
81 |
|
82 /** |
|
83 * Reset. |
|
84 */ |
|
85 void Reset(); |
|
86 |
|
87 /** |
|
88 * Close allocated resources. |
|
89 */ |
|
90 void Close(); |
|
91 |
|
92 /** |
|
93 * Get item count. |
|
94 */ |
|
95 TInt Count(); |
|
96 |
|
97 /** |
|
98 * Get entry. |
|
99 * |
|
100 * @param aIndex Index to Entry. |
|
101 */ |
|
102 ThspsDomStringPoolOptimizerEntry& Entry( const TInt aIndex ); |
|
103 |
|
104 private: |
|
105 /** |
|
106 * Find entry from alphabetic list. |
|
107 * Uses binary search. |
|
108 * |
|
109 * @param aString Reference to string to be searched for. |
|
110 * @param aLeft Left limit for binary search |
|
111 * @param aRight Right limit for binary search. |
|
112 * |
|
113 * @return Index to OPTIMIZER ARRAY. KErrNotFound if |
|
114 * given string is not found. |
|
115 */ |
|
116 TInt FindEntry( const TDesC8& aString, |
|
117 const TInt aLeft, |
|
118 const TInt aRight ); |
|
119 |
|
120 /** |
|
121 * Find a position clue for given string. |
|
122 * |
|
123 * Will return index that can be used to initiate linear |
|
124 * search. Uses binary search to limit required comparisons |
|
125 * when string pools starts to fill. |
|
126 * |
|
127 * Note: Returned index is not absolute! it must be |
|
128 * only used as a start index for linear searching. |
|
129 * |
|
130 * Returned index will be quite close to actual insertion position. |
|
131 * it will be 0 - 2 steps backward from actual position. |
|
132 * |
|
133 * @param aString Reference to string. |
|
134 * @param aLeft Left limit for binary search |
|
135 * @param aRight Right limit for binary search. |
|
136 * |
|
137 * @return Index to start searching for position |
|
138 * for given string. |
|
139 */ |
|
140 TInt FindInsertionIndexEstimate( const TDesC8& aString, |
|
141 const TInt aLeft, |
|
142 const TInt aRight ); |
|
143 |
|
144 private: // Data. |
|
145 /** |
|
146 * Array of optimizer entries. |
|
147 */ |
|
148 RArray<ThspsDomStringPoolOptimizerEntry> iEntries; |
|
149 }; |
|
150 |
|
151 #endif // HSPS_DOM_STRING_POOL_OPTIMIZER_H |
|
152 |
|
153 // End of File |