Merged in neo2buha/premake-dev (pull request #117)

Use seed for hashing
This commit is contained in:
Jason Perkins 2014-09-20 18:41:48 -04:00
parent 35b652557a
commit 05712c4ce7

View File

@ -1,7 +1,7 @@
/**
* \file string_hash.c
* \brief Computes a hash value for a string.
* \author Copyright (c) 2012 Jason Perkins and the Premake project
* \author Copyright (c) 2012-2014 Jason Perkins and the Premake project
*/
#include "premake.h"
@ -11,17 +11,18 @@
int string_hash(lua_State* L)
{
const char* str = luaL_checkstring(L, 1);
lua_pushnumber(L, (lua_Number)do_hash(str, 0));
return 1;
unsigned long seed = luaL_optint(L, 2, 0);
lua_pushnumber(L, do_hash(str, seed));
return 1;
}
unsigned long do_hash(const char* str, int seed)
{
/* DJB2 hashing; see http://www.cse.yorku.ca/~oz/hash.html */
unsigned long hash = 5381;
if (seed != 0) {
hash = hash * 33 + seed;
}