Skip to content

Commit

Permalink
Added hash pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
jwasham committed Apr 20, 2016
1 parent 99fbb2c commit 9c6a306
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
12 changes: 12 additions & 0 deletions algorithms/hash-pointer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

#include <limits.h>

#include "hash-pointer.h"

/* Hash function for a generic pointer */

unsigned int pointer_hash(void *location)
{
return (unsigned int) (unsigned long) location;
}

31 changes: 31 additions & 0 deletions algorithms/hash-pointer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

/**
* @file hash-pointer.h
*
* Hash function for a generic (void) pointer. See @ref pointer_hash.
*/

#ifndef ALGORITHM_HASH_POINTER_H
#define ALGORITHM_HASH_POINTER_H

#ifdef __cplusplus
extern "C" {
#endif

/**
* Generate a hash key for a pointer. The value pointed at by the pointer
* is not used, only the pointer itself.
*
* @param location The pointer
* @return A hash key for the pointer.
*/

unsigned int pointer_hash(void *location);

#ifdef __cplusplus
}
#endif

#endif /* #ifndef ALGORITHM_HASH_POINTER_H */


0 comments on commit 9c6a306

Please sign in to comment.