summaryrefslogtreecommitdiff
path: root/rts/Hash.h
diff options
context:
space:
mode:
authorCrazycolorz5 <Crazycolorz5@gmail.com>2019-01-20 19:26:58 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-12-11 14:12:17 -0500
commitf80c4a66ae219afa7bd4172441f4e94ba649c9d9 (patch)
tree34c3aa2cc484ade9b2460ca18941763fcb101fcc /rts/Hash.h
parent6e47a76a3d0a7b3d424442914478de579a49363c (diff)
downloadhaskell-f80c4a66ae219afa7bd4172441f4e94ba649c9d9.tar.gz
rts: Specialize hashing at call site rather than in struct.
Separate word and string hash tables on the type level, and do not store the hashing function. Thus when a different hash function is desire it is provided upon accessing the table. This is worst case the same as before the change, and in the majority of cases is better. Also mark the functions for aggressive inlining to improve performance. {F1686506} Reviewers: bgamari, erikd, simonmar Subscribers: rwbarton, thomie, carter GHC Trac Issues: #13165 Differential Revision: https://phabricator.haskell.org/D4889
Diffstat (limited to 'rts/Hash.h')
-rw-r--r--rts/Hash.h46
1 files changed, 32 insertions, 14 deletions
diff --git a/rts/Hash.h b/rts/Hash.h
index be388fb62f..59e2e22a09 100644
--- a/rts/Hash.h
+++ b/rts/Hash.h
@@ -11,6 +11,7 @@
#include "BeginPrivate.h"
typedef struct hashtable HashTable; /* abstract */
+typedef struct strhashtable StrHashTable;
/* Hash table access where the keys are StgWords.
* Values are passed into the hash table and stored as `const void *` values,
@@ -40,27 +41,44 @@ void mapHashTable(HashTable *table, void *data, MapHashFn fn);
* assumed to be allocated by the caller, and mustn't be deallocated
* until the corresponding hash table entry has been removed).
*/
-HashTable * allocStrHashTable ( void );
-
-#define lookupStrHashTable(table, key) \
- (lookupHashTable(table, (StgWord)key))
-
-#define insertStrHashTable(table, key, data) \
- (insertHashTable(table, (StgWord)key, data))
-
-#define removeStrHashTable(table, key, data) \
- (removeHashTable(table, (StgWord)key, data))
-
-/* Hash tables for arbitrary keys */
+INLINE_HEADER StrHashTable * allocStrHashTable ( void )
+{
+ return (StrHashTable*) allocHashTable();
+}
+
+void insertStrHashTable ( StrHashTable *table, const char * key,
+ const void *data );
+void * lookupStrHashTable ( const StrHashTable *table, const char * key);
+void * removeStrHashTable ( StrHashTable *table, const char * key,
+ const void *data );
+
+/*
+ * Hash tables for arbitrary key types.
+ * Generally, these functions allow for the specification of the
+ * HashFunction and CompareFunction. It's recommended that those
+ * are inlinable so there's a chance the compiler can discard
+ * some parameter-passing, as well as function calls, though note
+ * it's not guaranteed. Either way, the functions are parameters
+ * as the types should be statically known and thus
+ * storing them is unnecessary.
+ */
typedef int HashFunction(const HashTable *table, StgWord key);
typedef int CompareFunction(StgWord key1, StgWord key2);
-HashTable * allocHashTable_(HashFunction *hash, CompareFunction *compare);
int hashWord(const HashTable *table, StgWord key);
-int hashStr(const HashTable *table, StgWord key);
+int hashStr(const HashTable *table, StgWord w);
+void insertHashTable_ ( HashTable *table, StgWord key,
+ const void *data, HashFunction f );
+void * lookupHashTable_ ( const HashTable *table, StgWord key,
+ HashFunction f, CompareFunction cmp );
+void * removeHashTable_ ( HashTable *table, StgWord key,
+ const void *data, HashFunction f,
+ CompareFunction cmp );
/* Freeing hash tables
*/
void freeHashTable ( HashTable *table, void (*freeDataFun)(void *) );
+#define freeStrHashTable(table, f) \
+ (freeHashTable((HashTable*) table, f))
void exitHashTable ( void );