Commit 96890c5f authored by Philip Carns's avatar Philip Carns

Fix for bug reported by Noah Watkins: rename hash function to avoid

name space collisions in other libraries


git-svn-id: https://svn.mcs.anl.gov/repos/darshan/trunk@290 3b7491f3-a168-0410-bf4b-c445ed680a29
parent fc0ed994
......@@ -204,7 +204,7 @@ void darshan_shutdown_bench(int argc, char** argv, int rank, int nprocs);
void darshan_walk_file_accesses(struct darshan_job_runtime* final_job);
double darshan_wtime(void);
uint32_t hashlittle(const void *key, size_t length, uint32_t initval);
uint64_t hash(register unsigned char *k, register uint64_t length, register uint64_t level);
uint32_t darshan_hashlittle(const void *key, size_t length, uint32_t initval);
uint64_t darshan_hash(register unsigned char *k, register uint64_t length, register uint64_t level);
#endif /* __DARSHAN_H */
......@@ -543,7 +543,7 @@ int MPI_File_open(MPI_Comm comm, char *filename, int amode, MPI_Info info, MPI_F
{
CP_INC(file, CP_HINTS, 1);
}
tmp_hash = hash((void*)fh, sizeof(*fh), 0);
tmp_hash = darshan_hash((void*)fh, sizeof(*fh), 0);
hash_index = tmp_hash & CP_HASH_MASK;
file->fh_prev = NULL;
file->fh_next = darshan_global_job->fh_table[hash_index];
......@@ -580,7 +580,7 @@ int MPI_File_close(MPI_File *fh)
if(file->fh_prev == NULL)
{
/* head of fh hash table list */
tmp_hash = hash((void*)&tmp_fh, sizeof(tmp_fh), 0);
tmp_hash = darshan_hash((void*)&tmp_fh, sizeof(tmp_fh), 0);
hash_index = tmp_hash & CP_HASH_MASK;
darshan_global_job->fh_table[hash_index] = file->fh_next;
if(file->fh_next)
......@@ -1031,7 +1031,7 @@ static struct darshan_file_runtime* darshan_file_by_fh(MPI_File fh)
return(darshan_global_job->darshan_mru_file);
}
tmp_hash = hash((void*)(&fh), sizeof(fh), 0);
tmp_hash = darshan_hash((void*)(&fh), sizeof(fh), 0);
/* search hash table */
hash_index = tmp_hash & CP_HASH_MASK;
......@@ -1767,7 +1767,7 @@ static char* darshan_get_exe_and_mounts(struct darshan_job_runtime* final_job)
if(mnt_array_index < CP_MAX_MNTS)
{
mnt_hash_array[mnt_array_index] =
hash((void*)entry->mnt_dir, strlen(entry->mnt_dir), 0);
darshan_hash((void*)entry->mnt_dir, strlen(entry->mnt_dir), 0);
mnt_id_array[mnt_array_index] = tmp_st_dev;
mnt_array_index++;
}
......
......@@ -1181,7 +1181,7 @@ struct darshan_file_runtime* darshan_file_by_name(const char* name)
return(&darshan_global_job->file_runtime_array[0]);
}
tmp_hash = hash((void*)name, strlen(name), 0);
tmp_hash = darshan_hash((void*)name, strlen(name), 0);
/* check most recently used */
if(darshan_global_job->darshan_mru_file && darshan_global_job->darshan_mru_file->log_file->hash == tmp_hash)
......
......@@ -253,7 +253,7 @@ uint32_t *pb) /* IN: more seed OUT: secondary hash value */
/*
-------------------------------------------------------------------------------
hashlittle() -- hash a variable-length key into a 32-bit value
darshan_hashlittle() -- hash a variable-length key into a 32-bit value
k : the key (the unaligned variable-length array of bytes)
length : the length of the key, counting by bytes
initval : can be any 4-byte value
......@@ -278,7 +278,7 @@ acceptable. Do NOT use for cryptographic purposes.
-------------------------------------------------------------------------------
*/
uint32_t hashlittle( const void *key, size_t length, uint32_t initval)
uint32_t darshan_hashlittle( const void *key, size_t length, uint32_t initval)
{
uint32_t a,b,c; /* internal state */
union { const void *ptr; size_t i; } u; /* needed for Mac Powerbook G4 */
......
......@@ -54,7 +54,7 @@ This implies that a hash using mix64 has no funnels. There may be
/*
--------------------------------------------------------------------
hash() -- hash a variable-length key into a 64-bit value
darshan_hash() -- hash a variable-length key into a 64-bit value
k : the key (the unaligned variable-length array of bytes)
len : the length of the key, counting by bytes
level : can be any 8-byte value
......@@ -81,7 +81,7 @@ is acceptable. Do NOT use for cryptographic purposes.
--------------------------------------------------------------------
*/
ub8 hash( k, length, level)
ub8 darshan_hash( k, length, level)
const register ub1 *k; /* the key */
register ub8 length; /* the length of the key */
register ub8 level; /* the previous hash, or an arbitrary value */
......@@ -280,7 +280,7 @@ void driver1()
for (i=0; i<256; ++i)
{
h = hash(buf,i,h);
h = darshan_hash(buf,i,h);
}
}
......@@ -318,10 +318,10 @@ void driver2()
/* have a and b be two keys differing in only one bit */
a[i] ^= (k<<j);
a[i] ^= (k>>(8-j));
c[0] = hash(a, hlen, m);
c[0] = darshan_hash(a, hlen, m);
b[i] ^= ((k+1)<<j);
b[i] ^= ((k+1)>>(8-j));
d[0] = hash(b, hlen, m);
d[0] = darshan_hash(b, hlen, m);
/* check every bit is 1, 0, set, and not set at least once */
for (l=0; l<HASHSTATE; ++l)
{
......@@ -374,21 +374,21 @@ void driver3()
ub8 h,i,j,ref,x,y;
printf("Endianness. These should all be the same:\n");
h = hash(q+0, (ub8)(sizeof(q)-1), (ub8)0);
h = darshan_hash(q+0, (ub8)(sizeof(q)-1), (ub8)0);
printf("%.8lx%.8lx\n", (ub4)h, (ub4)(h>>32));
h = hash(qq+1, (ub8)(sizeof(q)-1), (ub8)0);
h = darshan_hash(qq+1, (ub8)(sizeof(q)-1), (ub8)0);
printf("%.8lx%.8lx\n", (ub4)h, (ub4)(h>>32));
h = hash(qqq+2, (ub8)(sizeof(q)-1), (ub8)0);
h = darshan_hash(qqq+2, (ub8)(sizeof(q)-1), (ub8)0);
printf("%.8lx%.8lx\n", (ub4)h, (ub4)(h>>32));
h = hash(qqqq+3, (ub8)(sizeof(q)-1), (ub8)0);
h = darshan_hash(qqqq+3, (ub8)(sizeof(q)-1), (ub8)0);
printf("%.8lx%.8lx\n", (ub4)h, (ub4)(h>>32));
h = hash(o+4, (ub8)(sizeof(q)-1), (ub8)0);
h = darshan_hash(o+4, (ub8)(sizeof(q)-1), (ub8)0);
printf("%.8lx%.8lx\n", (ub4)h, (ub4)(h>>32));
h = hash(oo+5, (ub8)(sizeof(q)-1), (ub8)0);
h = darshan_hash(oo+5, (ub8)(sizeof(q)-1), (ub8)0);
printf("%.8lx%.8lx\n", (ub4)h, (ub4)(h>>32));
h = hash(ooo+6, (ub8)(sizeof(q)-1), (ub8)0);
h = darshan_hash(ooo+6, (ub8)(sizeof(q)-1), (ub8)0);
printf("%.8lx%.8lx\n", (ub4)h, (ub4)(h>>32));
h = hash(oooo+7, (ub8)(sizeof(q)-1), (ub8)0);
h = darshan_hash(oooo+7, (ub8)(sizeof(q)-1), (ub8)0);
printf("%.8lx%.8lx\n", (ub4)h, (ub4)(h>>32));
printf("\n");
for (h=0, b=buf+1; h<8; ++h, ++b)
......@@ -399,11 +399,11 @@ void driver3()
for (j=0; j<i; ++j) *(b+j)=0;
/* these should all be equal */
ref = hash(b, len, (ub8)1);
ref = darshan_hash(b, len, (ub8)1);
*(b+i)=(ub1)~0;
*(b-1)=(ub1)~0;
x = hash(b, len, (ub8)1);
y = hash(b, len, (ub8)1);
x = darshan_hash(b, len, (ub8)1);
y = darshan_hash(b, len, (ub8)1);
if ((ref != x) || (ref != y))
{
printf("alignment error: %.8lx %.8lx %.8lx %ld %ld\n",ref,x,y,h,i);
......@@ -424,8 +424,8 @@ void driver3()
printf("These should all be different\n");
for (i=0, h=0; i<8; ++i)
{
h = hash(buf, (ub8)0, h);
printf("%2ld 0-byte strings, hash is %.8lx%.8lx\n", (ub4)i,
h = darshan_hash(buf, (ub8)0, h);
printf("%2ld 0-byte strings, darshan_hash is %.8lx%.8lx\n", (ub4)i,
(ub4)h,(ub4)(h>>32));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment