mirror of https://github.com/dnomd343/klotski.git
				
				
			
				 6 changed files with 56 additions and 44 deletions
			
			
		@ -0,0 +1,40 @@ | 
				
			|||||
 | 
					#pragma once | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					/// Provides XXH3 and MD5 hash calculation support. The former is far ahead in
 | 
				
			||||
 | 
					/// speed, but the latter is more of a commemorative significance.
 | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					#include "md5.h" | 
				
			||||
 | 
					#include "xxh3.h" | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					#include <vector> | 
				
			||||
 | 
					#include <cstdint> | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					namespace hash { | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					inline std::string md5(const void *data, const uint64_t size) { | 
				
			||||
 | 
					    return ::md5::MD5::Hash(data, size); | 
				
			||||
 | 
					} | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					inline uint64_t xxh3(const void *data, const uint64_t size) { | 
				
			||||
 | 
					    return XXH_INLINE_XXH3_64bits(data, size); | 
				
			||||
 | 
					} | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					inline std::string md5(const std::string_view &data) { | 
				
			||||
 | 
					    return md5(data.data(), data.size()); | 
				
			||||
 | 
					} | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					inline uint64_t xxh3(const std::string_view &data) { | 
				
			||||
 | 
					    return xxh3(data.data(), data.size()); | 
				
			||||
 | 
					} | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					template <typename T> | 
				
			||||
 | 
					inline std::string md5(const std::vector<T> &data) { | 
				
			||||
 | 
					    return md5(data.data(), data.size() * sizeof(T)); | 
				
			||||
 | 
					} | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					template <typename T> | 
				
			||||
 | 
					inline uint64_t xxh3(const std::vector<T> &data) { | 
				
			||||
 | 
					    return xxh3(data.data(), data.size() * sizeof(T)); | 
				
			||||
 | 
					} | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					} // namespace hash
 | 
				
			||||
@ -1,27 +0,0 @@ | 
				
			|||||
#pragma once | 
					 | 
				
			||||
 | 
					 | 
				
			||||
#include <string> | 
					 | 
				
			||||
#include "xxhash.h" | 
					 | 
				
			||||
 | 
					 | 
				
			||||
namespace xxhash { | 
					 | 
				
			||||
 | 
					 | 
				
			||||
std::string xxhsum(const void *data, size_t size) { | 
					 | 
				
			||||
    char *hash; | 
					 | 
				
			||||
    auto state = XXH64_createState(); | 
					 | 
				
			||||
    XXH64_reset(state, 0); | 
					 | 
				
			||||
    XXH64_update(state, data, size); | 
					 | 
				
			||||
    asprintf(&hash, "%016llx", XXH64_digest(state)); | 
					 | 
				
			||||
    XXH64_freeState(state); | 
					 | 
				
			||||
    return hash; | 
					 | 
				
			||||
} | 
					 | 
				
			||||
 | 
					 | 
				
			||||
std::string xxhsum(const std::string &data) { | 
					 | 
				
			||||
    return xxhsum(data.c_str(), data.length()); | 
					 | 
				
			||||
} | 
					 | 
				
			||||
 | 
					 | 
				
			||||
template <typename T> | 
					 | 
				
			||||
std::string xxhsum(const std::vector<T> &data) { | 
					 | 
				
			||||
    return xxhsum(data.data(), data.size() * sizeof(T)); | 
					 | 
				
			||||
} | 
					 | 
				
			||||
 | 
					 | 
				
			||||
} // namespace xxhsum
 | 
					 | 
				
			||||
					Loading…
					
					
				
		Reference in new issue