bool CMarkup::SetMapSize( int nSize, int nMap = 0 ) const;
The SetMapSize
method sets a hash table size for for the SavePos and RestorePos methods. If you don't set the size before using the table it will be the default size of just 7. For example if you know there will be thousands of elements with a unique id attribute you could map them for quick lookup as follows:
xml.SetMapSize( 10007 ); xml.ResetPos(); while ( xml.FindElem("//*[@id]") ) xml.SavePos( xml.GetAttrib("id") ); ... // Then later, return directly to any id xml.RestorPos( strID );
Generally, for the table size you use a prime number a bit larger than the number of identifiers you are likely to have. But it is not too critical; even if there are twice as many items than the table size it will still be quite fast. You can experiment with different table sizes on your sample data if that last ounce of performance is critical. Here are some example prime numbers: 53, 101, 211, 503, 1009, 2003, 10007, 20011, 50021, 100003, 200003, 500009.
The optional nMap
argument is used for additional maps. You can have any number of maps to save and restore positions of different pieces of indexing information. The default map is 0. Additional maps should be used sequentially 1, 2, 3 etc. The following example uses an additional map to support lookup of several hundred unique usernames. Notice the map number is specified in the save and restore position calls too.
#define MAP_USERNAME 1 xml.SetMapSize( 211, MAP_USERNAME ); xml.ResetPos(); while ( xml.FindElem("//username") ) xml.SavePos( xml.GetData(), MAP_USERNAME ); ... // Then later, return directly to any username xml.RestorPos( strUsername, MAP_USERNAME );
*Remember that all map information, including size, is lost on any SetDoc or Load.