Beispiel #1
0
Datei: 03.cpp Projekt: filaPro/my
std::string DoTestReverseUniqSort(size_t n) {
    TCounter::Reset();
    {
        TList<TCounter, std::allocator<TCounter>> lst;
        TList<int> lint;
        for (size_t i = 0; i < 2 * n; ++i) {
            lst.push_back(TCounter());
            lint.push_back(i / 2);
        }
        lst.reverse();
        lint.unique();
        if (lint.size() != n)
            return "lint.uniq(): wrong answer";
        lint.reverse();
        TList<int>::const_iterator it = lint.cbegin();
        for (size_t i = 0; i < n; ++i, ++it)
            if (*it != n - i - 1)
                return "lint.reverse(): wrong answer";
        lint.sort();
        it = lint.cbegin();
        for (size_t i = 0; i < n; ++i, ++it)
            if (*it != i)
                return "lint.sort(): wrong answer";
    }
    TCounter::CheckTotalOperationsCount(n * 10 + 100, 2 * n + 100);
    return TCounter::GetAllErrors();
}
Beispiel #2
0
Datei: 03.cpp Projekt: filaPro/my
std::string DoTestSplice(size_t n) {
    TCounter::Reset();
    {
        TList<TCounter, std::allocator<TCounter>> lst;
        for (size_t i = 0; i < n; ++i) {
            lst.push_back(TCounter());
        }
        TList<TCounter, std::allocator<TCounter>> lst1;
        for (size_t i = 0; i < n; ++i) {
            lst1.push_back(TCounter());
        }
        TList<TCounter, std::allocator<TCounter>>::iterator from = lst1.begin(), to = lst1.end();
        ++from;
        --to;
        lst.splice(lst.end(), lst1, from, to);
        if (lst.size() != 2 * n - 2 || lst1.size() != 2)
            return "lst.splice() or lst.size(): wrong answer";
        lst.resize(n);
        if (lst.size() != n)
            return "lst.resize(): wrong answer";
        lst1.splice(lst1.end(), lst);
        if (lst1.size() != n + 2 || lst.size() != 0)
            return "lst.splice() or lst.size(): wrong answer";
    }
    TCounter::CheckTotalOperationsCount(n * 10 + 100, n * 2 + 100);
    return TCounter::GetAllErrors();
}
Beispiel #3
0
Datei: 03.cpp Projekt: filaPro/my
std::string DoTestFrontBack(size_t n) {
    TCounter::Reset();
    {
        constexpr int M = 10;
        TCounter data[M];
        TList<TCounter, std::allocator<TCounter>> lst;
        for (size_t i = 0; i < n; ++i) {
            lst.push_back(TCounter(data[i % M]));
        }
        if (lst.size() != n)
            return "lst.size(): wrong answer";
        if (lst.back().GetData() != data[(n + M - 1) % M].GetData())
            return "lst.back(): wrong answer";
        if (lst.front().GetData() != data[0].GetData())
            return "lst.front(): wrong answer";
        while (!lst.empty())
            lst.pop_back();
        for (size_t i = 0; i < n; ++i) {
            lst.push_front(TCounter(data[i % M]));
        }
        if (lst.size() != n)
            return "lst.size(): wrong answer";
        if (lst.front().GetData() != data[(n + M - 1) % M].GetData())
            return "lst.back(): wrong answer";
        if (lst.back().GetData() != data[0].GetData())
            return "lst.front(): wrong answer";
        while (!lst.empty())
            lst.pop_front();
    }
    TCounter::CheckTotalOperationsCount(n * 10 + 100, n + 100);
    return TCounter::GetAllErrors();
}
Beispiel #4
0
Datei: 03.cpp Projekt: filaPro/my
std::string DoTestMove(size_t n) {
    TCounter::Reset();
    {
        TList<TCounter, std::allocator<TCounter>> lst;
        for (size_t i = 0; i < n; ++i) {
            lst.push_back(TCounter());
        }
        TList<TCounter> mv = std::move(lst);
        lst.swap(mv);
    }
    TCounter::CheckTotalOperationsCount(n * 5 + 100, n + 100);
    return TCounter::GetAllErrors();
}
Beispiel #5
0
void TimerMaster::InternalAddTimer(
    TimerSlot *slot,
    boost::weak_ptr<Timer> weak_timer,
    int jiffies) {
  int i = 0;
  int idx  = jiffies - timer_jiffies_;
  TList *v = NULL;
  int expires = jiffies;
  uint64 upper = 1;
  for (int i = 0; i < arraysize(vecs_); ++i) {
    upper <<= kTVBits;
    if (idx < upper) {
      int j = expires & kTVMask;
      v = &vecs_[i][j];
      break;
    }
    expires >>= kTVBits;
  }
  CHECK(v != NULL);
  slot->weak_timer = weak_timer;
  slot->jiffies = jiffies;
  v->push_back(*slot);
}