12 #ifndef YAPF_COSTCACHE_HPP 13 #define YAPF_COSTCACHE_HPP 15 #include "../../date_func.h" 22 template <
class Types>
26 typedef typename Types::Tpf
Tpf;
27 typedef typename Types::NodeList::Titem
Node;
53 template <
class Types>
57 typedef typename Types::Tpf
Tpf;
58 typedef typename Types::NodeList::Titem
Node;
59 typedef typename Node::Key
Key;
60 typedef typename Node::CachedData CachedData;
61 typedef typename CachedData::Key CacheKey;
65 LocalCache m_local_cache;
70 return *
static_cast<Tpf *
>(
this);
80 CacheKey key(n.GetKey());
81 Yapf().ConnectNodeToCachedData(n, *
new (m_local_cache.
Append()) CachedData(key));
108 s_rail_change_counter++;
123 template <
class Tsegment>
125 static const int C_HASH_BITS = 14;
129 typedef typename Tsegment::Key
Key;
143 inline Tsegment& Get(Key &key,
bool *found)
145 Tsegment *item = m_map.
Find(key);
148 item =
new (m_heap.
Append()) Tsegment(key);
162 template <
class Types>
166 typedef typename Types::Tpf
Tpf;
167 typedef typename Types::NodeList::Titem
Node;
168 typedef typename Node::Key
Key;
169 typedef typename Node::CachedData CachedData;
170 typedef typename CachedData::Key CacheKey;
174 Cache &m_global_cache;
181 return *
static_cast<Tpf *
>(
this);
184 inline static Cache& stGetGlobalCache()
186 static int last_rail_change_counter = 0;
187 static Date last_date = 0;
191 if (last_date !=
_date) {
193 DEBUG(yapf, 2,
"Pf time today: %5d ms", _total_pf_time_us / 1000);
194 _total_pf_time_us = 0;
198 if (last_rail_change_counter != Cache::s_rail_change_counter) {
199 last_rail_change_counter = Cache::s_rail_change_counter;
212 if (!Yapf().CanUseGlobalCache(n)) {
213 return Tlocal::PfNodeCacheFetch(n);
215 CacheKey key(n.GetKey());
217 CachedData &item = m_global_cache.Get(key, &found);
218 Yapf().ConnectNodeToCachedData(n, item);
bool PfNodeCacheFetch(Node &n)
Called by YAPF to attach cached or local segment cost data to the given node.
Types::NodeList::Titem Node
this will be our node type
void PfNodeCacheFlush(Node &n)
Called by YAPF to flush the cached segment cost data back into cache storage.
void Push(Titem_ &new_item)
add one item - copy it from the given item
Track
These are used to specify a single track.
CSegmentCostCacheT - template class providing hash-map and storage (heap) of Tsegment structures...
CYapfSegmentCostCacheNoneT - the formal only yapf cost cache provider that implements PfNodeCacheFetc...
Tsegment::Key Key
key to hash table
T * Append()
allocate but not construct new item
void Clear()
Clear (destroy) all items.
Types::NodeList::Titem Node
this will be our node type
static int s_rail_change_counter
if any track changes, this counter is incremented - that will invalidate segment cost cache ...
void PfNodeCacheFlush(Node &n)
Called by YAPF to flush the cached segment cost data back into cache storage.
const Titem_ * Find(const Tkey &key) const
const item search
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Types::NodeList::Titem Node
this will be our node type
void PfNodeCacheFlush(Node &n)
Called by YAPF to flush the cached segment cost data back into cache storage.
void Clear()
simple clear - forget all items - used by CSegmentCostCacheT.Flush()
bool PfNodeCacheFetch(Node &n)
Called by YAPF to attach cached or local segment cost data to the given node.
Tpf & Yapf()
to access inherited path finder
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Tpf & Yapf()
to access inherited path finder
#define DEBUG(name, level,...)
Output a line of debugging information.
CYapfSegmentCostCacheGlobalT - the yapf cost cache provider that adds the segment cost caching functi...
Base class for segment cost cache providers.
CYapfSegmentCostCacheLocalT - the yapf cost cache provider that implements fake segment cost caching ...
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
uint32 TileIndex
The index/ID of a Tile.
void Flush()
flush (clear) the cache
Node::Key Key
key to hash tables
int32 Date
The type to store our dates in.
Date _date
Current date in days (day counter)
Node::Key Key
key to hash tables
bool PfNodeCacheFetch(Node &n)
Called by YAPF to attach cached or local segment cost data to the given node.