10 #ifndef YAPF_COSTCACHE_HPP
11 #define YAPF_COSTCACHE_HPP
13 #include "../../misc/hashtable.hpp"
14 #include "../../tile_type.h"
15 #include "../../track_type.h"
22 template <
class Types>
26 typedef typename Types::Tpf
Tpf;
27 typedef typename Types::NodeList::Item
Node;
67 template <
class Tsegment>
69 static constexpr
int HASH_BITS = 14;
71 using Key =
typename Tsegment::Key;
74 std::deque<Tsegment> heap;
85 inline Tsegment &Get(
Key &key,
bool *found)
87 Tsegment *item = this->map.
Find(key);
88 if (item ==
nullptr) {
90 item = &this->heap.emplace_back(key);
91 this->map.
Push(*item);
104 template <
class Types>
107 typedef typename Types::Tpf
Tpf;
108 typedef typename Types::NodeList::Item
Node;
109 typedef typename Node::Key
Key;
110 typedef typename Node::CachedData CachedData;
111 typedef typename CachedData::Key CacheKey;
113 using LocalCache = std::deque<CachedData>;
117 LocalCache local_cache;
124 return *
static_cast<Tpf *
>(
this);
127 inline static Cache &stGetGlobalCache()
129 static int last_rail_change_counter = 0;
147 CacheKey key(n.GetKey());
149 if (!
Yapf().CanUseGlobalCache(n)) {
150 Yapf().ConnectNodeToCachedData(n, this->local_cache.emplace_back(key));
155 CachedData &item = this->global_cache.Get(key, &found);
156 Yapf().ConnectNodeToCachedData(n, item);
CYapfSegmentCostCacheGlobalT - the yapf cost cache provider that adds the segment cost caching functi...
bool PfNodeCacheFetch(Node &n)
Called by YAPF to attach cached or local segment cost data to the given node.
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Node::Key Key
key to hash tables
Tpf & Yapf()
to access inherited path finder
Types::NodeList::Item Node
this will be our node type
CYapfSegmentCostCacheNoneT - the formal only yapf cost cache provider that implements PfNodeCacheFetc...
bool PfNodeCacheFetch(Node &)
Called by YAPF to attach cached or local segment cost data to the given node.
Types::NodeList::Item Node
this will be our node type
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
const Titem * Find(const Tkey &key) const
const item search
void Push(Titem &new_item)
add one item - copy it from the given item
void Clear()
simple clear - forget all items - used by CSegmentCostCacheT.Flush()
Base class for segment cost cache providers.
static int s_rail_change_counter
if any track changes, this counter is incremented - that will invalidate segment cost cache
CSegmentCostCacheT - template class providing hash-map and storage (heap) of Tsegment structures.
void Flush()
flush (clear) the cache
typename Tsegment::Key Key
key to hash table
Track
These are used to specify a single track.