Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmake/warnings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ no_warning(comma-subscript)
no_warning(ambiguous-reversed-operator)
no_warning(restrict)
no_warning(free-nonheap-object)
no_warning(unneeded-internal-declaration)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
no_warning(stringop-overflow)
endif()
Expand Down Expand Up @@ -169,4 +170,4 @@ if(MSVC)
# C4061: Switch statement case not handled

message(STATUS "MSVC warning configuration applied - suppressed informational warnings, kept bug-indicating warnings")
endif()
endif()
30 changes: 16 additions & 14 deletions features/car/restrictions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -120,30 +120,32 @@ Feature: Car - Turn restrictions
# https://www.openstreetmap.org/edit?node=54878482#map=19/34.05242/-117.19067
Given the node map
"""
c
3
a 1 x 2 b
4
d

y c
a x b
z d
"""

And the ways
| nodes |
| ya |
| za |
| ax |
| xb |
| bx |
| cx |
| xd |
| dx |

And the relations
| type | way:from | way:to | node:via | restriction |
| restriction | ax | ax | x | no_u_turn |
| restriction | bx | bx | x | no_u_turn |
| restriction | cx | cx | x | no_u_turn |
| restriction | dx | dx | x | no_u_turn |
| type | way:from | way:to | node:via | restriction |
| restriction | ax | ax | x | no_u_turn |
| restriction | bx | bx | x | no_u_turn |
| restriction | cx | cx | x | no_u_turn |
| restriction | dx | dx | x | no_u_turn |
| restriction | za | ya | a | no_left_turn |

When I route I should get
| waypoints | route | turns |
| a,x,a | ax,xb,xb,xb,ax,ax | depart,new name straight,continue uturn,arrive,depart,arrive |
| waypoints | route | turns |
| z,y | za,ax,bx,bx,ax,ya,ya | depart,new name right,new name straight,continue uturn,new name straight,turn right,arrive |

@no_turning
Scenario: Car - Handle any no_* relation
Expand Down
8 changes: 0 additions & 8 deletions features/testbot/alternative.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ Feature: Alternative route
Background:
Given the profile "testbot"
And a grid size of 200 meters
# Force data preparation to single-threaded to ensure consistent
# results for alternative generation during tests (alternative
# finding is highly sensitive to graph shape, which is in turn
# affected by parallelism during generation)
And the contract extra arguments "--threads 1"
And the extract extra arguments "--threads 1"
And the customize extra arguments "--threads 1"
And the partition extra arguments "--threads 1"

And the node map
"""
Expand Down
23 changes: 7 additions & 16 deletions features/testbot/alternative_loop.feature
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
@routing @testbot @alternative @isolated @todo
@routing @testbot @alternative
Feature: Alternative route

Background:
Given the profile "testbot"
Given a grid size of 200 meters
# Force data preparation to single-threaded to ensure consistent
# results for alternative generation during tests (alternative
# finding is highly sensitive to graph shape, which is in turn
# affected by parallelism during generation)
And the contract extra arguments "--threads 1"
And the extract extra arguments "--threads 1"
And the customize extra arguments "--threads 1"
And the partition extra arguments "--threads 1"

Scenario: Alternative Loop Paths
Given the node map
Expand Down Expand Up @@ -40,10 +32,9 @@ Feature: Alternative route
| 7 | 8 | ca,ab,bd,dc,ca,ca | |


@with_mld
Scenario: Alternative loop paths on a single node with an asymmetric circle
# The test checks only MLD implementation, alternatives results are unpredictable for CH on windows (#4691, #4693)
Given a grid size of 10 meters

Given the node map
"""
a b c
Expand All @@ -56,15 +47,15 @@ Feature: Alternative route
And the nodes
| node | barrier |
| i | bollard |
| g | bollard |

And the ways
| nodes | oneway |
| abcdefghijkla | no |
| nodes | oneway |
| abcdefg | no |
| ghijkla | no |

And the query options
| alternatives | true |

When I route I should get
| from | to | route | alternative | weight |
| e | k | abcdefghijkla,abcdefghijkla | abcdefghijkla,abcdefghijkla | 6.8 |
| from | to | route | alternative | weight |
| a | g | ghijkla,ghijkla | abcdefg,abcdefg | 6.8 |
4 changes: 2 additions & 2 deletions include/contractor/contractor_heap.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef OSRM_CONTRACTOR_CONTRACTOR_HEAP_HPP_
#define OSRM_CONTRACTOR_CONTRACTOR_HEAP_HPP_

#include "util/linear_hash_storage.hpp"
#include "util/query_heap.hpp"
#include "util/typedefs.hpp"
#include "util/xor_fast_hash_storage.hpp"

namespace osrm::contractor
{
Expand All @@ -20,7 +20,7 @@ using ContractorHeap = util::QueryHeap<NodeID,
NodeID,
EdgeWeight,
ContractorHeapData,
util::XORFastHashStorage<NodeID, NodeID>>;
util::LinearHashStorage<NodeID, NodeID>>;

} // namespace osrm::contractor

Expand Down
119 changes: 119 additions & 0 deletions include/util/linear_hash_storage.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#ifndef LINEAR_HASH_STORAGE
#define LINEAR_HASH_STORAGE

#include <concepts>
#include <cstdlib>
#include <limits>
#include <vector>

namespace osrm::util
{

/**
* @brief A hash table using open addressing with linear probing.
*
* Use this table only if the key is a NodeID.
*
* This hash table has a fixed maximum size. The size will always be rounded up to the
* next power of 2. The hash function is a simple bitwise AND with a mask (as faster
* replacement for a modulo function). Its performance degrades with occupancy. With
* occupancy at 50% it performs faster than std::unordered_map, at 90% it performs
* slower than std::unordered_map.
*
* @tparam KeyType
* @tparam ValueType
*
* For an introduction to linear probing see:
* https://opendatastructures.org/ods-cpp/5_2_Linear_Probing.html#SECTION00923000000000000000
*/
template <typename KeyType, typename ValueType>
requires std::unsigned_integral<KeyType>
class LinearHashStorage
Comment on lines +5 to +31
{

private:
struct HashCell
{
unsigned time;
KeyType key;
ValueType value;
HashCell()
: time(std::numeric_limits<unsigned>::max()), key(std::numeric_limits<KeyType>::max()),
value(std::numeric_limits<ValueType>::max())
{
}
};

std::vector<HashCell> cells;
unsigned current_timestamp;
std::size_t mask;

public:
explicit LinearHashStorage(std::size_t size) : current_timestamp{0u}
{
// round up to the next power of two
// See: Figure 3.3 in Warren Henry S., Hacker's Delight, 2nd ed., Pearson 2013
--size;
size = size | (size >> 1);
size = size | (size >> 2);
size = size | (size >> 4);
size = size | (size >> 8);
size = size | (size >> 16);
size = size | (size >> 32);
mask = size;
++size;

cells.resize(size);
}

ValueType &operator[](const KeyType key)
{
std::size_t position = key & mask;
while ((cells[position].time == current_timestamp) && (cells[position].key != key))
{
++position &= mask;
}
Comment on lines +69 to +75
auto p = &cells[position];
if (p->time != current_timestamp)
{
p->time = current_timestamp;
p->key = key;
p->value = std::numeric_limits<ValueType>::max();
}
return p->value;
}

// peek into table, get key for node, think of it as a read-only operator[]
ValueType peek_index(const KeyType key) const
{
std::size_t position = key & mask;
while ((cells[position].time == current_timestamp) && (cells[position].key != key))
{
++position &= mask;
}
return cells[position].time == current_timestamp ? cells[position].value
: std::numeric_limits<ValueType>::max();
}

bool contains(const KeyType key) const
{
std::size_t position = key & mask;
while ((cells[position].time == current_timestamp) && (cells[position].key != key))
{
++position &= mask;
}
return cells[position].time == current_timestamp;
}

void Clear()
{
++current_timestamp;
if (std::numeric_limits<unsigned>::max() == current_timestamp)
{
cells.clear();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BS. current_timestamp will overflow to 0 and reset itself.

}
}
};
} // namespace osrm::util

#endif // LINEAR_HASH_STORAGE
67 changes: 0 additions & 67 deletions include/util/xor_fast_hash.hpp

This file was deleted.

Loading
Loading