GeoDesk for C++
Fast and storage-efficient spatial database engine for OpenStreetMap features
Loading...
Searching...
No Matches
sorting.h
Go to the documentation of this file.
1// Copyright (c) 2024 Clarisma / GeoDesk contributors
2// SPDX-License-Identifier: LGPL-3.0-only
3
4#pragma once
5
6#include <utility>
7
8namespace clarisma {
9
10namespace sorting
11{
12 template <typename ItemType, typename KeyType, typename IndexType, IndexType Sentinel>
13 void rearrage(ItemType* items, std::pair< KeyType,IndexType>* indices, size_t count)
14 {
15 for (size_t i = 0; i < count; ++i)
16 {
17 if (indices[i].second == -1) continue; // Skip if this index is part of a previously processed cycle
18
19 size_t j = i;
20 ItemType tempItem = items[i];
21
22 while (indices[j].second != Sentinel)
23 {
24 size_t next_j = indices[j].second;
25 if (next_j == i)
26 {
27 items[j] = tempItem;
28 indices[j].second = Sentinel; // Mark as visited
29 break;
30 }
31 else
32 {
33 items[j] = items[next_j];
34 indices[j].second = Sentinel; // Mark as visited
35 }
36 j = next_j;
37 }
38 }
39 }
40}
41
42
43} // namespace clarisma
Definition Arena.h:17