Can the result of the BobJenkinsHash function be negative?

Environment: Win7 64bit, Delphi 2010, Win32 project.

I am trying to get integer hash values ​​for a rowset using the BobJenkinsHash () function from Generics.Defaults.

It works, but some points are not clear to me.

  • Can a function result be negative?

As I see on the source site , uint32_t is used as the result of the hashword () function type:

uint32_t hashword(
const uint32_t *k,                   /* the key, an array of uint32_t values  */
size_t          length,               /* the length of the key, in uint32_ts    */
uint32_t        initval)         /* the previous hash, or an arbitrary value */
{

Is this an unsigned int?

  1. Second question: I have different results for different rows with the same values:

    'DEFPROD001' => 759009858
    'DEFPROD001' => 1185633302
    

Is this normal behavior?

My complete function is to calculate the hash (if the first argument is empty and then the second is returned):

function TAmWriterJD.ComposeID(const defaultID: string; const GUID: String): String;
var
  bjh: Integer;
begin
  if defaultID = '' then
  begin
    Result := GUID
  end
  else
  begin
    bjh := BobJenkinsHash(defaultID, Length(defaultID) * SizeOf(defaultID), 0);
    Result := IntToStr(bjh);
  end;
end;
+4
source share
1

Delphi :

function BobJenkinsHash(const Data; Len, InitData: Integer): Integer;

32- . , .

C, , 32 . .

, , , , 32 . , .

, - . , , .

BobJenkinsHash(defaultID, Length(defaultID) * SizeOf(defaultID), 0);

defaultID string . . - . :

BobJenkinsHash(Pointer(defaultID)^, Length(defaultID) * SizeOf(Char), 0);

:

{$APPTYPE CONSOLE}

uses
  System.Generics.Defaults;

var
  s, t: string;

begin
  s := 'DEFPROD001';
  t := 'DEFPROD001';

  Writeln(BobJenkinsHash(s, Length(s) * SizeOf(s), 0));
  Writeln(BobJenkinsHash(t, Length(t) * SizeOf(t), 0));

  Writeln(BobJenkinsHash(Pointer(s)^, Length(s) * SizeOf(Char), 0));
  Writeln(BobJenkinsHash(Pointer(t)^, Length(t) * SizeOf(Char), 0));

  Readln;
end.

:

2129045826
-331457644
-161666357
-161666357
+7

Source: https://habr.com/ru/post/1653103/


All Articles