yapf/yapf_costcache.hpp
changeset 5129 15e48dea98a5
parent 5083 6da97b6fbbd6
child 5568 75f13d7bfaed
equal deleted inserted replaced
5128:c75525088fb9 5129:15e48dea98a5
   102 	HashTable    m_map;
   102 	HashTable    m_map;
   103 	Heap         m_heap;
   103 	Heap         m_heap;
   104 
   104 
   105 	FORCEINLINE CSegmentCostCacheT() {}
   105 	FORCEINLINE CSegmentCostCacheT() {}
   106 
   106 
       
   107 	/** flush (clear) the cache */
       
   108 	FORCEINLINE void Flush() {m_map.Clear(); m_heap.Clear();};
       
   109 
   107 	FORCEINLINE Tsegment& Get(Key& key, bool *found)
   110 	FORCEINLINE Tsegment& Get(Key& key, bool *found)
   108 	{
   111 	{
   109 		Tsegment* item = m_map.Find(key);
   112 		Tsegment* item = m_map.Find(key);
   110 		if (item == NULL) {
   113 		if (item == NULL) {
   111 			*found = false;
   114 			*found = false;
   141 	FORCEINLINE CYapfSegmentCostCacheGlobalT() : m_global_cache(stGetGlobalCache()) {};
   144 	FORCEINLINE CYapfSegmentCostCacheGlobalT() : m_global_cache(stGetGlobalCache()) {};
   142 
   145 
   143 	/// to access inherited path finder
   146 	/// to access inherited path finder
   144 	FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
   147 	FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
   145 
   148 
   146 	FORCEINLINE static Cache*& stGlobalCachePtr() {static Cache* pC = NULL; return pC;}
       
   147 
       
   148 	FORCEINLINE static Cache& stGetGlobalCache()
   149 	FORCEINLINE static Cache& stGetGlobalCache()
   149 	{
   150 	{
   150 		static int last_rail_change_counter = 0;
   151 		static int last_rail_change_counter = 0;
   151 		static Date last_date = 0;
   152 		static Date last_date = 0;
       
   153 		static Cache C;
   152 
   154 
   153 		// some statistics
   155 		// some statistics
   154 		if (last_date != _date) {
   156 		if (last_date != _date) {
   155 			last_date = _date;
   157 			last_date = _date;
   156 			DEBUG(yapf, 1) ("pf time today:%5d ms", _total_pf_time_us / 1000);
   158 			DEBUG(yapf, 1) ("pf time today:%5d ms", _total_pf_time_us / 1000);
   157 			_total_pf_time_us = 0;
   159 			_total_pf_time_us = 0;
   158 		}
   160 		}
   159 
   161 
   160 		Cache*& pC = stGlobalCachePtr();
       
   161 
       
   162 		// delete the cache sometimes...
   162 		// delete the cache sometimes...
   163 		if (pC != NULL && last_rail_change_counter != Cache::s_rail_change_counter) {
   163 		if (last_rail_change_counter != Cache::s_rail_change_counter) {
   164 			last_rail_change_counter = Cache::s_rail_change_counter;
   164 			last_rail_change_counter = Cache::s_rail_change_counter;
   165 			delete pC;
   165 			C.Flush();
   166 			pC = NULL;
       
   167 		}
   166 		}
   168 
   167 		return C;
   169 		if (pC == NULL)
       
   170 			pC = new Cache();
       
   171 		return *pC;
       
   172 	}
   168 	}
   173 
   169 
   174 public:
   170 public:
   175 	/** Called by YAPF to attach cached or local segment cost data to the given node.
   171 	/** Called by YAPF to attach cached or local segment cost data to the given node.
   176 	 *  @return true if globally cached data were used or false if local data was used */
   172 	 *  @return true if globally cached data were used or false if local data was used */