Skip to content

Instantly share code, notes, and snippets.

@FinchPowers
Last active December 18, 2015 01:48
Show Gist options
  • Save FinchPowers/5706305 to your computer and use it in GitHub Desktop.
Save FinchPowers/5706305 to your computer and use it in GitHub Desktop.
#pragma once
#include <city.h>
#include <sstream>
void michHashInternal(std::stringstream& ss){}
template<typename first, typename... args>
void michHashInternal(std::stringstream& ss, first&& f, args&&... a){
ss << std::forward<first>(f);
michHashInternal(ss, std::forward<args>(a)...);
}
template<typename... args>
uint64 michHash(args&&... a){
std::stringstream ss;
michHashInternal(ss, std::forward<args>(a)...);
std::string str = ss.str();
return CityHash64(str.c_str(), str.length());
}
@RAttab
Copy link

RAttab commented Jun 4, 2013

get rid of first on michHash.
argument passing should be either be std::forwarded (so add a && to the arguments and std::forward(f) on access or do it by const&. For both functions.
Get rid of strlen. You already have the size in ss.str() so avoid recomputing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment