Exemplo n.º 1
0
void PreRanker::Filter(bool viewportSearch)
{
  using TSet = set<impl::PreResult1, LessFeatureID>;
  TSet theSet;

  sort(m_results.begin(), m_results.end(), ComparePreResult1());
  m_results.erase(unique(m_results.begin(), m_results.end(), EqualFeatureID()), m_results.end());

  sort(m_results.begin(), m_results.end(), &impl::PreResult1::LessDistance);

  if (m_limit != 0 && m_results.size() > m_limit)
  {
    // Priority is some kind of distance from the viewport or
    // position, therefore if we have a bunch of results with the same
    // priority, we have no idea here which results are relevant.  To
    // prevent bias from previous search routines (like sorting by
    // feature id) this code randomly selects tail of the
    // sorted-by-priority list of pre-results.

    double const last = m_results[m_limit - 1].GetDistance();

    auto b = m_results.begin() + m_limit - 1;
    for (; b != m_results.begin() && b->GetDistance() == last; --b)
      ;
    if (b->GetDistance() != last)
      ++b;

    auto e = m_results.begin() + m_limit;
    for (; e != m_results.end() && e->GetDistance() == last; ++e)
      ;

    // The main reason of shuffling here is to select a random subset
    // from the low-priority results. We're using a linear
    // congruential method with default seed because it is fast,
    // simple and doesn't need an external entropy source.
    //
    // TODO (@y, @m, @vng): consider to take some kind of hash from
    // features and then select a subset with smallest values of this
    // hash.  In this case this subset of results will be persistent
    // to small changes in the original set.
    minstd_rand engine;
    shuffle(b, e, engine);
  }
  theSet.insert(m_results.begin(), m_results.begin() + min(m_results.size(), m_limit));

  if (!viewportSearch)
  {
    size_t n = min(m_results.size(), m_limit);
    nth_element(m_results.begin(), m_results.begin() + n, m_results.end(),
                &impl::PreResult1::LessRank);
    theSet.insert(m_results.begin(), m_results.begin() + n);
  }

  m_results.reserve(theSet.size());
  m_results.clear();
  copy(theSet.begin(), theSet.end(), back_inserter(m_results));
}
Exemplo n.º 2
0
 void TestCtorHelper(TSet & set)
 {
     IS_TRUE(set.empty());
     IS_TRUE(set.size() == 0);
     IS_TRUE(set.begin() == set.end());
     IS_TRUE(set.cbegin() == set.cend());
     IS_TRUE(set.rbegin() == set.rend());
     IS_TRUE(set.crbegin() == set.crend());
 }
Exemplo n.º 3
0
bool FBullCowGame::IsIsogram(FString Guess) const {
  if (Guess.length() < 2) return true;

  TSet<char> set;
  for (char Letter : Guess) {
    Letter = tolower(Letter);
    if (set.find(Letter) != set.end()) return false;
    else set.insert(Letter);
  }
}
Exemplo n.º 4
0
void CCueDocument::GetMediaFiles(vector<std::string>& mediaFiles)
{
  typedef set<std::string> TSet;
  TSet uniqueFiles;
  for (Tracks::const_iterator it = m_tracks.begin(); it != m_tracks.end(); ++it)
    uniqueFiles.insert(it->strFile);

  for (TSet::const_iterator it = uniqueFiles.begin(); it != uniqueFiles.end(); it++)
    mediaFiles.push_back(*it);
}