Array *Array::SortArrayElementsByKey() {
    Array *newARRAY = new(AllocArray(PIF))Array(PIF);

#ifdef STDMAP_KEYS
    if (Keys) {
        KeyMap::iterator end = Keys->end();
        AnsiString key;
        ARRAY_COUNT_TYPE i = 0;
        for (KeyMap::iterator iter = Keys->begin(); iter != end; ++iter) {
            newARRAY->Add(Get(iter->second));
            key = (char *)iter->first;
            newARRAY->AddKey(&key, i++);
        }
    }
#else
    CleanIndex(true);
    for (ARRAY_COUNT_TYPE i = 0; i < KeysCount; i++) {
        AnsiString key = Keys [i].KEY;
        newARRAY->Add(Get(Keys [i].index));
        newARRAY->AddKey(&key, i);
    }
#endif

    return newARRAY;
}
Beispiel #2
0
void UserMarkGenerator::UpdateIndex(kml::MarkGroupId groupId)
{
  for (auto & tileGroups : m_index)
  {
    auto itGroupIndexes = tileGroups.second->find(groupId);
    if (itGroupIndexes != tileGroups.second->end())
    {
      itGroupIndexes->second->m_markIds.clear();
      itGroupIndexes->second->m_lineIds.clear();
    }
  }

  auto const groupIt = m_groups.find(groupId);
  if (groupIt == m_groups.end())
    return;

  IDCollections & idCollection = *groupIt->second;

  for (auto markId : idCollection.m_markIds)
  {
    UserMarkRenderParams const & params = *m_marks[markId];
    for (int zoomLevel = params.m_minZoom; zoomLevel <= scales::GetUpperScale(); ++zoomLevel)
    {
      TileKey const tileKey = GetTileKeyByPoint(params.m_pivot, zoomLevel);
      auto groupIDs = GetIdCollection(tileKey, groupId);
      groupIDs->m_markIds.push_back(markId);
    }
  }

  for (auto lineId : idCollection.m_lineIds)
  {
    UserLineRenderParams const & params = *m_lines[lineId];

    int const startZoom = GetNearestLineIndexZoom(params.m_minZoom);
    for (int zoomLevel : kLineIndexingLevels)
    {
      if (zoomLevel < startZoom)
        continue;
      // Process spline by segments that are no longer than tile size.
      double const maxLength = MercatorBounds::kRangeX / (1 << (zoomLevel - 1));

      df::ProcessSplineSegmentRects(params.m_spline, maxLength,
                                    [&](m2::RectD const & segmentRect)
      {
        CalcTilesCoverage(segmentRect, zoomLevel, [&](int tileX, int tileY)
        {
          TileKey const tileKey(tileX, tileY, zoomLevel);
          auto groupIDs = GetIdCollection(tileKey, groupId);
          groupIDs->m_lineIds.push_back(lineId);
        });
        return true;
      });
    }
  }

  CleanIndex();
}
ARRAY_COUNT_TYPE Array::AddKey(AnsiString *KEY, ARRAY_COUNT_TYPE index) {
#ifdef STDMAP_KEYS
    if (!Keys)
        Keys = new KeyMap();

    int  len  = KEY->Length();
    char *buf = (char *)FAST_MALLOC(len + 1);
    memcpy(buf, KEY->c_str(), len);
    buf[len] = 0;
    Keys->insert(KeyMapPair(buf, index));
    return Keys->size();
#else
    if (!(KeysCount % KEY_INCREMENT))
        Keys = (ArrayKey *)FAST_REALLOC(Keys, sizeof(ArrayKey) * (KeysCount / KEY_INCREMENT + 1) * KEY_INCREMENT);
    ARRAY_COUNT_TYPE place = FindPlace(KEY->c_str());

    int len = KEY->Length();
    ARRAY_COUNT_TYPE delta = KeysCount - place;
    char             dirty = 0;

    if ((KeysCount > DIRTY_TRESHOLD) && (delta)) {
        ARRAY_COUNT_TYPE delta_place = 0;
        place  = FindPlace(KEY->c_str(), &delta_place);
        place += delta_place;
        delta  = KeysCount - place;
        dirty  = 1;
    }

    if (place < KeysCount)
        memmove((void *)&Keys [place + 1], (void *)&Keys [place], sizeof(ArrayKey) * delta);

    Keys [place].KEY   = (char *)FAST_MALLOC(len + 1);
    Keys [place].index = index;
    Keys [place].dirty = dirty;
    memcpy(Keys [place].KEY, KEY->c_str(), len);
    Keys [place].KEY [len] = 0;
    KeysCount++;
    CleanIndex();

    return KeysCount;
#endif
}
void Array::GetKeys(char **container, int size) {
    memset(container, 0, size * sizeof(char *));
#ifdef STDMAP_KEYS
    if (Keys) {
        KeyMap::iterator end = Keys->end();
        AnsiString key;
        ARRAY_COUNT_TYPE i = 0;
        for (KeyMap::iterator iter = Keys->begin(); iter != end; ++iter) {
            key = (char *)iter->first;
            if ((iter->second >= 0) && (iter->second < size))
                container[iter->second] = key;
        }
    }
#else
    CleanIndex(true);
    for (ARRAY_COUNT_TYPE i = 0; i < KeysCount; i++) {
        if ((Keys [i].index >= 0) && (Keys [i].index < size))
            container[Keys [i].index] = Keys [i].KEY;
    }
#endif
}