From 05712c4ce75d2c8e4125793e9f6a3f57168716b4 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Sat, 20 Sep 2014 18:41:48 -0400 Subject: [PATCH] Merged in neo2buha/premake-dev (pull request #117) Use seed for hashing --- src/host/string_hash.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/host/string_hash.c b/src/host/string_hash.c index f5403381..65814bcb 100644 --- a/src/host/string_hash.c +++ b/src/host/string_hash.c @@ -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; }