mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 13:03:36 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
28
coding/move_to_front.cpp
Normal file
28
coding/move_to_front.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "coding/move_to_front.hpp"
|
||||
|
||||
#include "base/assert.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <numeric>
|
||||
|
||||
namespace coding
|
||||
{
|
||||
MoveToFront::MoveToFront()
|
||||
{
|
||||
std::iota(m_order.begin(), m_order.end(), 0);
|
||||
}
|
||||
|
||||
uint8_t MoveToFront::Transform(uint8_t b)
|
||||
{
|
||||
auto const it = std::find(m_order.begin(), m_order.end(), b);
|
||||
ASSERT(it != m_order.end(), ());
|
||||
|
||||
size_t const result = std::distance(m_order.begin(), it);
|
||||
ASSERT_LESS(result, kNumBytes, ());
|
||||
|
||||
std::rotate(m_order.begin(), it, it + 1);
|
||||
ASSERT_EQUAL(m_order[0], b, ());
|
||||
return static_cast<uint8_t>(result);
|
||||
}
|
||||
} // namespace coding
|
||||
Reference in New Issue
Block a user