From ea36c255dccb0f549c708af14ed53b53e078d763 Mon Sep 17 00:00:00 2001 From: Constantin Shalnev Date: Mon, 7 Dec 2015 11:54:57 +0300 Subject: [PATCH] Renamed popped to evicted --- map/gps_track_collection.cpp | 19 +++--- map/gps_track_collection.hpp | 8 +-- map/map_tests/gps_track_collection_test.cpp | 74 ++++++++++----------- 3 files changed, 51 insertions(+), 50 deletions(-) diff --git a/map/gps_track_collection.cpp b/map/gps_track_collection.cpp index 005aed34ce..145ae88952 100644 --- a/map/gps_track_collection.cpp +++ b/map/gps_track_collection.cpp @@ -16,7 +16,8 @@ class Rollbacker { public: Rollbacker(deque & cont) - : m_cont(&cont) , m_size(cont.size()) + : m_cont(&cont) + , m_size(cont.size()) {} ~Rollbacker() { @@ -40,24 +41,24 @@ GpsTrackCollection::GpsTrackCollection(size_t maxSize, hours duration) { } -size_t GpsTrackCollection::Add(TItem const & item, pair & poppedIds) +size_t GpsTrackCollection::Add(TItem const & item, pair & evictedIds) { if (!m_items.empty() && m_items.back().m_timestamp > item.m_timestamp) { // Invalid timestamp order - poppedIds = make_pair(kInvalidId, kInvalidId); // Nothing was popped + evictedIds = make_pair(kInvalidId, kInvalidId); // Nothing was evicted return kInvalidId; // Nothing was added } m_items.emplace_back(item); ++m_lastId; - poppedIds = RemoveExtraItems(); + evictedIds = RemoveExtraItems(); return m_lastId - 1; } -pair GpsTrackCollection::Add(vector const & items, pair & poppedIds) +pair GpsTrackCollection::Add(vector const & items, pair & evictedIds) { size_t startId = m_lastId; size_t added = 0; @@ -79,13 +80,13 @@ pair GpsTrackCollection::Add(vector const & items, pair GpsTrackCollection::Clear(bool resetIds) ASSERT(m_lastId >= m_items.size(), ()); - // Range of popped items + // Range of evicted items auto const res = make_pair(m_lastId - m_items.size(), m_lastId - 1); // Use move from an empty deque to free memory. @@ -190,7 +191,7 @@ pair GpsTrackCollection::RemoveExtraItems() auto i = m_items.begin(); // First, try linear search for short distance. It is common case for sliding window - // when new items will pop up old items. + // when new items will evict old items. for (size_t j = 0; j < kLinearSearchCount && !found; ++i, ++j) { ASSERT(i != m_items.end(), ()); diff --git a/map/gps_track_collection.hpp b/map/gps_track_collection.hpp index b96b51092d..045787a19f 100644 --- a/map/gps_track_collection.hpp +++ b/map/gps_track_collection.hpp @@ -22,18 +22,18 @@ public: /// Adds new point in the collection. /// @param item - item to be added. - /// @param poppedIds - output, which contains range of identifiers popped items or + /// @param evictedIds - output, which contains range of identifiers evicted items or /// pair(kInvalidId,kInvalidId) if nothing was removed /// @returns the item unique identifier or kInvalidId if point has incorrect time. - size_t Add(TItem const & item, pair & poppedIds); + size_t Add(TItem const & item, pair & evictedIds); /// Adds set of new points in the collection. /// @param items - set of items to be added. - /// @param poppedIds - output, which contains range of identifiers popped items or + /// @param evictedIds - output, which contains range of identifiers evicted items or /// pair(kInvalidId,kInvalidId) if nothing was removed /// @returns range of identifiers of added items or pair(kInvalidId,kInvalidId) if nothing was added /// @note items which does not conform to timestamp sequence, is not added. - pair Add(vector const & items, pair & poppedIds); + pair Add(vector const & items, pair & evictedIds); /// Get current duration in hours /// @returns current duration in hours diff --git a/map/map_tests/gps_track_collection_test.cpp b/map/map_tests/gps_track_collection_test.cpp index 494953bb81..0479da5b98 100644 --- a/map/map_tests/gps_track_collection_test.cpp +++ b/map/map_tests/gps_track_collection_test.cpp @@ -32,11 +32,11 @@ UNIT_TEST(GpsTrackCollection_Simple) for (size_t i = 0; i < 50; ++i) { auto info = MakeGpsTrackInfo(timestamp + i, ms::LatLon(-90 + i, -180 + i), i); - pair poppedId; - size_t addedId = collection.Add(info, poppedId); + pair evictedIds; + size_t addedId = collection.Add(info, evictedIds); TEST_EQUAL(addedId, i, ()); - TEST_EQUAL(poppedId.first, GpsTrackCollection::kInvalidId, ()); - TEST_EQUAL(poppedId.second, GpsTrackCollection::kInvalidId, ()); + TEST_EQUAL(evictedIds.first, GpsTrackCollection::kInvalidId, ()); + TEST_EQUAL(evictedIds.second, GpsTrackCollection::kInvalidId, ()); data[addedId] = info; } @@ -60,7 +60,7 @@ UNIT_TEST(GpsTrackCollection_Simple) TEST_EQUAL(0, collection.GetSize(), ()); } -UNIT_TEST(GpsTrackCollection_PopByTimestamp) +UNIT_TEST(GpsTrackCollection_EvictedByTimestamp) { double const timestamp = system_clock::to_time_t(system_clock::now()); double const timestamp_1h = timestamp + 60 * 60; @@ -68,24 +68,24 @@ UNIT_TEST(GpsTrackCollection_PopByTimestamp) GpsTrackCollection collection(100, hours(24)); - pair poppedId; - size_t addedId = collection.Add(MakeGpsTrackInfo(timestamp, ms::LatLon(-90, -180), 1), poppedId); + pair evictedIds; + size_t addedId = collection.Add(MakeGpsTrackInfo(timestamp, ms::LatLon(-90, -180), 1), evictedIds); TEST_EQUAL(addedId, 0, ()); - TEST_EQUAL(poppedId.first, GpsTrackCollection::kInvalidId, ()); - TEST_EQUAL(poppedId.second, GpsTrackCollection::kInvalidId, ()); + TEST_EQUAL(evictedIds.first, GpsTrackCollection::kInvalidId, ()); + TEST_EQUAL(evictedIds.second, GpsTrackCollection::kInvalidId, ()); - addedId = collection.Add(MakeGpsTrackInfo(timestamp_1h, ms::LatLon(90, 180), 2), poppedId); + addedId = collection.Add(MakeGpsTrackInfo(timestamp_1h, ms::LatLon(90, 180), 2), evictedIds); TEST_EQUAL(addedId, 1, ()); - TEST_EQUAL(poppedId.first, GpsTrackCollection::kInvalidId, ()); - TEST_EQUAL(poppedId.second, GpsTrackCollection::kInvalidId, ()); + TEST_EQUAL(evictedIds.first, GpsTrackCollection::kInvalidId, ()); + TEST_EQUAL(evictedIds.second, GpsTrackCollection::kInvalidId, ()); TEST_EQUAL(2, collection.GetSize(), ()); auto lastInfo = MakeGpsTrackInfo(timestamp_25h, ms::LatLon(45, 60), 3); - addedId = collection.Add(lastInfo, poppedId); + addedId = collection.Add(lastInfo, evictedIds); TEST_EQUAL(addedId, 2, ()); - TEST_EQUAL(poppedId.first, 0, ()); - TEST_EQUAL(poppedId.second, 1, ()); + TEST_EQUAL(evictedIds.first, 0, ()); + TEST_EQUAL(evictedIds.second, 1, ()); TEST_EQUAL(1, collection.GetSize(), ()); @@ -106,7 +106,7 @@ UNIT_TEST(GpsTrackCollection_PopByTimestamp) TEST_EQUAL(0, collection.GetSize(), ()); } -UNIT_TEST(GpsTrackCollection_PopByCount) +UNIT_TEST(GpsTrackCollection_EvictedByCount) { double const timestamp = system_clock::to_time_t(system_clock::now()); @@ -119,22 +119,22 @@ UNIT_TEST(GpsTrackCollection_PopByCount) for (size_t i = 0; i < 100; ++i) { auto info = MakeGpsTrackInfo(timestamp + i, ms::LatLon(-90 + i, -180 + i), i); - pair poppedId; - size_t addedId = collection.Add(info, poppedId); + pair evictedIds; + size_t addedId = collection.Add(info, evictedIds); TEST_EQUAL(addedId, i, ()); - TEST_EQUAL(poppedId.first, GpsTrackCollection::kInvalidId, ()); - TEST_EQUAL(poppedId.second, GpsTrackCollection::kInvalidId, ()); + TEST_EQUAL(evictedIds.first, GpsTrackCollection::kInvalidId, ()); + TEST_EQUAL(evictedIds.second, GpsTrackCollection::kInvalidId, ()); data[addedId] = info; } TEST_EQUAL(100, collection.GetSize(), ()); auto info = MakeGpsTrackInfo(timestamp + 100, ms::LatLon(45, 60), 110); - pair poppedId; - size_t addedId = collection.Add(info, poppedId); + pair evictedIds; + size_t addedId = collection.Add(info, evictedIds); TEST_EQUAL(addedId, 100, ()); - TEST_EQUAL(poppedId.first, 0, ()); - TEST_EQUAL(poppedId.second, 0, ()); + TEST_EQUAL(evictedIds.first, 0, ()); + TEST_EQUAL(evictedIds.second, 0, ()); data[addedId] = info; TEST_EQUAL(100, collection.GetSize(), ()); @@ -159,7 +159,7 @@ UNIT_TEST(GpsTrackCollection_PopByCount) TEST_EQUAL(0, collection.GetSize(), ()); } -UNIT_TEST(GpsTrackCollection_PopByTimestamp2) +UNIT_TEST(GpsTrackCollection_EvictedByTimestamp2) { double const timestamp = 0; double const timestamp_12h = timestamp + 12 * 60 * 60; @@ -172,11 +172,11 @@ UNIT_TEST(GpsTrackCollection_PopByTimestamp2) for (size_t i = 0; i < 500; ++i) { auto info = MakeGpsTrackInfo(timestamp + i, ms::LatLon(-90 + i, -180 + i), i); - pair poppedId; - size_t addedId = collection.Add(info, poppedId); + pair evictedIds; + size_t addedId = collection.Add(info, evictedIds); TEST_EQUAL(addedId, i, ()); - TEST_EQUAL(poppedId.first, GpsTrackCollection::kInvalidId, ()); - TEST_EQUAL(poppedId.second, GpsTrackCollection::kInvalidId, ()); + TEST_EQUAL(evictedIds.first, GpsTrackCollection::kInvalidId, ()); + TEST_EQUAL(evictedIds.second, GpsTrackCollection::kInvalidId, ()); } auto time = collection.GetTimestampRange(); @@ -186,11 +186,11 @@ UNIT_TEST(GpsTrackCollection_PopByTimestamp2) for (size_t i = 0; i < 500; ++i) { auto info = MakeGpsTrackInfo(timestamp_12h + i, ms::LatLon(-90 + i, -180 + i), i); - pair poppedId; - size_t addedId = collection.Add(info, poppedId); + pair evictedIds; + size_t addedId = collection.Add(info, evictedIds); TEST_EQUAL(addedId, 500 + i, ()); - TEST_EQUAL(poppedId.first, GpsTrackCollection::kInvalidId, ()); - TEST_EQUAL(poppedId.second, GpsTrackCollection::kInvalidId, ()); + TEST_EQUAL(evictedIds.first, GpsTrackCollection::kInvalidId, ()); + TEST_EQUAL(evictedIds.second, GpsTrackCollection::kInvalidId, ()); } time = collection.GetTimestampRange(); @@ -198,11 +198,11 @@ UNIT_TEST(GpsTrackCollection_PopByTimestamp2) TEST_EQUAL(1000, collection.GetSize(), ()); auto info = MakeGpsTrackInfo(timestamp_35h, ms::LatLon(45, 60), 110); - pair poppedId; - size_t addedId = collection.Add(info, poppedId); + pair evictedIds; + size_t addedId = collection.Add(info, evictedIds); TEST_EQUAL(addedId, 1000, ()); - TEST_EQUAL(poppedId.first, 0, ()); - TEST_EQUAL(poppedId.second, 499, ()); + TEST_EQUAL(evictedIds.first, 0, ()); + TEST_EQUAL(evictedIds.second, 499, ()); auto res = collection.Clear(); TEST_EQUAL(res.first, 500, ());