/** * Sort the interim StringTable and store it to the real protobuf StringTable. * while storing to the real table, this function fills the id2id_map with * pairs, mapping the interim-ids to final and real StringTable ids. * * Note that the m_strings table is a std::map and as such is sorted lexicographically. * When the transformation into the sortedby multimap is done, it gets sorted by * the count. The end result (at least with the glibc standard container/algorithm * implementation) is that the string table is sorted first by reverse count (ie descending) * and then by reverse lexicographic order. */ void store_stringtable(OSMPBF::StringTable* st) { typedef std::multimap<string_info, std::string> cmap; cmap sortedbycount; m_id2id_map.resize(m_size+1); std::transform(m_strings.begin(), m_strings.end(), std::inserter(sortedbycount, sortedbycount.begin()), flip_pair<std::string, string_info>); int n=0; cmap::const_iterator end=sortedbycount.end(); for (cmap::const_iterator it = sortedbycount.begin(); it != end; ++it) { // add the string of the current item to the pbf StringTable st->add_s(it->second); // store the mapping from the interim-id to the real id m_id2id_map[it->first.interim_id] = ++n; } }
/** * Sort the interim StringTable and store it to the real protobuf StringTable. * while storing to the real table, this function fills the id2id_map with * pairs, mapping the interim-ids to final and real StringTable ids. * * Note that the m_strings table is a std::map and as such is sorted lexicographically. * When the transformation into the sortedby multimap is done, it gets sorted by * the count. The end result (at least with the glibc standard container/algorithm * implementation) is that the string table is sorted first by reverse count (ie descending) * and then by reverse lexicographic order. */ void store_stringtable(OSMPBF::StringTable* st) { // add empty StringTable entry at index 0 // StringTable index 0 is reserved as delimiter in the densenodes key/value list // this line also ensures that there's always a valid StringTable st->add_s(""); typedef std::multimap<string_info, std::string> cmap; cmap sortedbycount; m_id2id_map.resize(m_size+1); std::transform(m_strings.begin(), m_strings.end(), std::inserter(sortedbycount, sortedbycount.begin()), flip_pair<std::string, string_info>); int n=0; cmap::const_iterator end=sortedbycount.end(); for (cmap::const_iterator it = sortedbycount.begin(); it != end; ++it) { // add the string of the current item to the pbf StringTable st->add_s(it->second); // store the mapping from the interim-id to the real id m_id2id_map[it->first.interim_id] = ++n; } }