projects
/
libfirm
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added missing API docu, improved existing API docu
[libfirm]
/
include
/
libfirm
/
adt
/
hashptr.h
diff --git
a/include/libfirm/adt/hashptr.h
b/include/libfirm/adt/hashptr.h
index
918843e
..
ed6844f
100644
(file)
--- a/
include/libfirm/adt/hashptr.h
+++ b/
include/libfirm/adt/hashptr.h
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (C) 1995-20
08
University of Karlsruhe. All right reserved.
+ * Copyright (C) 1995-20
11
University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
*
* This file is part of libFirm.
*
@@
-19,15
+19,22
@@
/**
* @file
/**
* @file
- * @brief Hash function
for pointer
s
+ * @brief Hash functions
* @author Michael Beck, Sebastian Hack
* @author Michael Beck, Sebastian Hack
- * @version $Id$
*/
#ifndef FIRM_ADT_HASHPTR_H
#define FIRM_ADT_HASHPTR_H
*/
#ifndef FIRM_ADT_HASHPTR_H
#define FIRM_ADT_HASHPTR_H
-#include "firm_config.h"
-#include "compiler.h"
+#include <stdlib.h>
+#include "../begin.h"
+
+/**
+ * @ingroup algorithms
+ * @defgroup hashptr Hash Functions
+ * @{
+ */
+
+/** @cond DISABLED */
#define _FIRM_FNV_OFFSET_BASIS 2166136261U
#define _FIRM_FNV_FNV_PRIME 16777619U
#define _FIRM_FNV_OFFSET_BASIS 2166136261U
#define _FIRM_FNV_FNV_PRIME 16777619U
@@
-35,9
+42,14
@@
/* Computing x * _FIRM_FNV_FNV_PRIME */
#define _FIRM_FNV_TIMES_PRIME(x) ((x) * _FIRM_FNV_FNV_PRIME)
/* Computing x * _FIRM_FNV_FNV_PRIME */
#define _FIRM_FNV_TIMES_PRIME(x) ((x) * _FIRM_FNV_FNV_PRIME)
-static INLINE unsigned firm_fnv_hash(const unsigned char *data, unsigned bytes)
+/** @endcond */
+
+/**
+ * Returns a hash value for a block of data.
+ */
+static inline unsigned hash_data(const unsigned char *data, size_t bytes)
{
{
-
unsigned
i;
+
size_t
i;
unsigned hash = _FIRM_FNV_OFFSET_BASIS;
for(i = 0; i < bytes; ++i) {
unsigned hash = _FIRM_FNV_OFFSET_BASIS;
for(i = 0; i < bytes; ++i) {
@@
-48,56
+60,51
@@
static INLINE unsigned firm_fnv_hash(const unsigned char *data, unsigned bytes)
return hash;
}
return hash;
}
-static INLINE unsigned firm_fnv_hash_str(const char *data)
+/**
+ * Returns a hash value for a string.
+ * @param str The string (can be const).
+ * @return A hash value for the string.
+ */
+static inline unsigned hash_str(const char *str)
{
unsigned i;
unsigned hash = _FIRM_FNV_OFFSET_BASIS;
{
unsigned i;
unsigned hash = _FIRM_FNV_OFFSET_BASIS;
- for(i = 0;
data
[i] != '\0'; ++i) {
+ for(i = 0;
str
[i] != '\0'; ++i) {
hash = _FIRM_FNV_TIMES_PRIME(hash);
hash = _FIRM_FNV_TIMES_PRIME(hash);
- hash ^=
data
[i];
+ hash ^=
str
[i];
}
return hash;
}
/**
}
return hash;
}
/**
- * hash a pointer value: Pointer addresses are mostly aligned to 4
- * or 8 bytes. So we remove the lowest 3 bits
+ * Returns a hash value for a pointer.
+ * Pointer addresses are mostly aligned to 4 or 8 bytes. So we remove the
+ * lowest 3 bits.
*/
*/
-#define HASH_PTR(ptr) ((unsigned)(((char *) (ptr) - (char *)0) >> 3))
+static inline unsigned hash_ptr(const void *ptr)
+{
+ return ((unsigned)(((char *) (ptr) - (char *)0) >> 3));
+}
/**
/**
- *
Hash a string
.
- * @param
str The string (can be const)
.
- * @param
len The length of the string
.
- * @return
A hash value for the string
.
+ *
Combines 2 hash values
.
+ * @param
x One hash value
.
+ * @param
y Another hash value
.
+ * @return
A hash value computed from both
.
*/
*/
-#define HASH_STR(str,len) firm_fnv_hash((const unsigned char *) (str), (len))
-
-#ifdef _MSC_VER
-#pragma warning(disable:4307)
-#endif /* _MSC_VER */
-
-static INLINE unsigned _hash_combine(unsigned x, unsigned y)
+static inline unsigned hash_combine(unsigned x, unsigned y)
{
{
- unsigned hash = _FIRM_FNV_TIMES_PRIME(_FIRM_FNV_OFFSET_BASIS);
- hash ^= x;
- hash = _FIRM_FNV_TIMES_PRIME(hash);
- hash ^= y;
- return hash;
+
unsigned hash = _FIRM_FNV_TIMES_PRIME(_FIRM_FNV_OFFSET_BASIS);
+
hash ^= x;
+
hash = _FIRM_FNV_TIMES_PRIME(hash);
+
hash ^= y;
+
return hash;
}
}
-#ifdef _MSC_VER
-#pragma warning(default:4307)
-#endif /* _MSC_VER */
+/** @} */
-/**
- * Make one hash value out of two others.
- * @param a One hash value.
- * @param b Another hash value.
- * @return A hash value computed from the both.
- */
-#define HASH_COMBINE(a,b) _hash_combine(a, b)
+#include "../end.h"
#endif
#endif