Subject: Re: [Ips] Perfect Hashing for All 23 iSCSI Text Keys

From: Ming Zhang <[email-masked]>
Date: Wed, 01 Jun 2005 08:48:03 -0400

any particular reason for hashing in a space with 23 value?

ming

On Sun, 2005-05-29 at 01:10 -0700, Faraz Ahmed wrote:
> Hi all;
>       I dont know whether this should be discussed here. As part of
> implementing a iSCSI target, we often need to search for a particular Text
> key. Here i have discovered a hashing fucntion which perfectly hashes all
> the 23 iSCSI text key.
>      The Bernsteins Hash Function wiht the MAGIC value of 34043539 hashes
> all the keys perfectly.
> 
> 
> 
> #define FARAZ_HASH_VAL 34043539
> #define PR_COL  0
> #define IDX_COL 1
> char __key_hash[MAX_KEYS][2];
> 
> 
> 
> /*
>  * Berstein Hash Fucntion for strings. Hashes all the keys uniquely
>  */
> inline int __djb2_hash(char *str_orig)
> {
> unsigned long hash = FARAZ_HASH_VAL;
> char *str = str_orig;
> int c;
>  while ((c=*str++)!='\0')
>    hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
> 
>  iSCSIDEBUGINFO("__djb2_hash(%s)=%d",str_orig,(int)hash%MAX_KEYS);
> 
>  return hash%MAX_KEYS;
> }
> 
> 
> _______________________________________________
> Ips mailing list
> [email-masked]
> https://www1.ietf.org/mailman/listinfo/ips
_______________________________________________
Ips mailing list
[email-masked]
https://www1.ietf.org/mailman/listinfo/ips

---

From: "Faraz Ahmed" <[email-masked]>
Date: Wed, 1 Jun 2005 07:11:42 -0700

Hi Ming;
 Its just a finding i thought that should be shared. Any ways the
optimization may minuscule, since the space being small. But I think its
better than

if(!strcmp()) elseuif (!strcmp()) my first implementation
the lexical sort/search the second one

Anyways is there some very easy, very obvious way to do this search, which
is better than the hash thing in terms of time. Do let me know. May be i
have just overlooked an approach. or tried to optimize something that is in
the end going to optimize nothing in the large scheme of work.

Regards
Faraz

----- Original Message ----- 
From: "Ming Zhang" <[email-masked]>
To: "Faraz Ahmed" <[email-masked]>
Cc: "Nicholas A. Bellinger" <[email-masked]>; <[email-masked]>;
<[email-masked]>; "linux-iscsi development team"
<[email-masked]>
Sent: Wednesday, June 01, 2005 5:48 AM
Subject: [linux-iscsi-devel] Re: [Ips] Perfect Hashing for All 23 iSCSI Text
Keys

---

From: Ming Zhang <[email-masked]>
Date: Wed, 01 Jun 2005 09:55:19 -0400

>  Its just a finding i thought that should be shared. Any ways the
yes, always thanks on this.

> if(!strcmp()) elseuif (!strcmp()) my first implementation
my current implementation. :P

> the lexical sort/search the second one
not even think about this. :P too complex for me.

> the end going to optimize nothing in the large scheme of work.
i donot know why you need to find the text key frequently. i assumed we
only do it when setup a connection. so i prefer to spending optimization
effort on data transfer path.

ming