Vaizard/MurmurHash3PHP — Issue #6: Suggested Improvement
Author: diegomontoya
Created: 2011-12-11 08:20:35+00:00
State: open

Here is the suggestions change:

(1) Right now, murmurhash3() requires at least 2 parms. data + data length. Change: remove requirement for data length and calculate strlen() within the extension itself. Make it a lot easier to use and faster.

(2) Change: Make sure that we ERROR out and not return a NULL if the passed parameter is incorrect number or type. This is very important so that we don't have hidden php warnings.

(3) Change: When passing an optional seed parameter make sure it's also a LONG value.

Below is the snippet of code changes.

PHP_FUNCTION(murmurhash3)
{
char *key;

long seed;
char output[MURMURHASH3_OUTPUT_LENGTH + 1];
char result[MURMURHASH3_OUTPUT_LENGTH * 2 + 1];

// Parse the input parameters
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &key, &seed) == FAILURE) {
zend_error(E_ERROR, "murmurhash3 expects a string followed by an optional long!");
}

// Calculate the hash
MurmurHash3_x64_128 (key, strlen(key), (uint32_t)seed, output );