mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-10-30 19:22:31 +00:00 
			
		
		
		
	Add specialized hash() for type dict and use a dict instead of a std::map for techmap_cache and techmap_do_cache.
				
					
				
			This commit is contained in:
		
							parent
							
								
									437f3fb342
								
							
						
					
					
						commit
						2fb4931e5b
					
				
					 3 changed files with 25 additions and 10 deletions
				
			
		|  | @ -19,6 +19,12 @@ | |||
| 
 | ||||
| namespace hashlib { | ||||
| 
 | ||||
| template<typename T> struct hash_ops; | ||||
| template<typename K, typename T, typename OPS = hash_ops<K>> class dict; | ||||
| template<typename K, int offset = 0, typename OPS = hash_ops<K>> class idict; | ||||
| template<typename K, typename OPS = hash_ops<K>> class pool; | ||||
| template<typename K, typename OPS = hash_ops<K>> class mfp; | ||||
| 
 | ||||
| const int hashtable_size_trigger = 2; | ||||
| const int hashtable_size_factor = 3; | ||||
| 
 | ||||
|  | @ -100,6 +106,20 @@ template<typename P, typename Q> struct hash_ops<std::pair<P, Q>> { | |||
| 	} | ||||
| }; | ||||
| 
 | ||||
| template<typename P, typename Q> struct hash_ops<dict<P, Q>> { | ||||
| 	static inline bool cmp(dict<P, Q> a, dict<P, Q> b) { | ||||
| 		return a == b; | ||||
| 	} | ||||
| 	static inline unsigned int hash(dict<P, Q> a) { | ||||
| 		unsigned int h = mkhash_init; | ||||
| 		for (auto &it : a) { | ||||
| 			h = mkhash(h, hash_ops<P>::hash(it.first)); | ||||
| 			h = mkhash(h, hash_ops<Q>::hash(it.second)); | ||||
| 		} | ||||
| 		return h; | ||||
| 	} | ||||
| }; | ||||
| 
 | ||||
| template<typename... T> struct hash_ops<std::tuple<T...>> { | ||||
| 	static inline bool cmp(std::tuple<T...> a, std::tuple<T...> b) { | ||||
| 		return a == b; | ||||
|  | @ -191,11 +211,6 @@ inline int hashtable_size(int min_size) | |||
| 	throw std::length_error("hash table exceeded maximum size."); | ||||
| } | ||||
| 
 | ||||
| template<typename K, typename T, typename OPS = hash_ops<K>> class dict; | ||||
| template<typename K, int offset = 0, typename OPS = hash_ops<K>> class idict; | ||||
| template<typename K, typename OPS = hash_ops<K>> class pool; | ||||
| template<typename K, typename OPS = hash_ops<K>> class mfp; | ||||
| 
 | ||||
| template<typename K, typename T, typename OPS> | ||||
| class dict | ||||
| { | ||||
|  |  | |||
|  | @ -150,7 +150,7 @@ namespace RTLIL | |||
| 			if (!p[0]) | ||||
| 				return 0; | ||||
| 
 | ||||
| 			log_assert(p[0] == '$' || p[0] == '\\'); | ||||
| 			log_assert(p[0] == '$' || p[0] == '\\' || strncmp(p, "_TECHMAP_", strlen("_TECHMAP_")) == 0); | ||||
| 			log_assert(p[1] != 0); | ||||
| 
 | ||||
| 			auto it = global_id_index_.find((char*)p); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue