mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 05:19:11 +00:00 
			
		
		
		
	hashlib: hash_t can be set to 64-bit
This commit is contained in:
		
							parent
							
								
									b8738e2bd7
								
							
						
					
					
						commit
						582259f770
					
				
					 1 changed files with 19 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -54,9 +54,9 @@ namespace hashlib {
 | 
			
		|||
const int hashtable_size_trigger = 2;
 | 
			
		||||
const int hashtable_size_factor = 3;
 | 
			
		||||
 | 
			
		||||
#define DJB2_BROKEN_SIZE
 | 
			
		||||
#define DJB2_32
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifdef DJB2_BROKEN_SIZE
 | 
			
		||||
 | 
			
		||||
template<typename T>
 | 
			
		||||
struct hash_ops;
 | 
			
		||||
| 
						 | 
				
			
			@ -76,8 +76,13 @@ inline unsigned int mkhash_xorshift(unsigned int a) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
class Hasher {
 | 
			
		||||
	public: //TODO
 | 
			
		||||
	public:
 | 
			
		||||
	#ifdef DJB2_32
 | 
			
		||||
	using hash_t = uint32_t;
 | 
			
		||||
	#endif
 | 
			
		||||
	#ifdef DJB2_64
 | 
			
		||||
	using hash_t = uint64_t;
 | 
			
		||||
	#endif
 | 
			
		||||
 | 
			
		||||
	Hasher() {
 | 
			
		||||
		// traditionally 5381 is used as starting value for the djb2 hash
 | 
			
		||||
| 
						 | 
				
			
			@ -128,7 +133,6 @@ class Hasher {
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
template<typename T>
 | 
			
		||||
struct hash_ops {
 | 
			
		||||
| 
						 | 
				
			
			@ -201,6 +205,17 @@ template<typename T> struct hash_ops<std::vector<T>> {
 | 
			
		|||
	}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template<typename T, size_t N> struct hash_ops<std::array<T, N>> {
 | 
			
		||||
    static inline bool cmp(std::array<T, N> a, std::array<T, N> b) {
 | 
			
		||||
        return a == b;
 | 
			
		||||
    }
 | 
			
		||||
    static inline Hasher hash_acc(std::array<T, N> a, Hasher h) {
 | 
			
		||||
        for (const auto& k : a)
 | 
			
		||||
            h = hash_ops<T>::hash_acc(k, h);
 | 
			
		||||
        return h;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct hash_cstr_ops {
 | 
			
		||||
	static inline bool cmp(const char *a, const char *b) {
 | 
			
		||||
		for (int i = 0; a[i] || b[i]; i++)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue