summaryrefslogtreecommitdiff
path: root/hash.h
diff options
context:
space:
mode:
Diffstat (limited to 'hash.h')
-rw-r--r--hash.h72
1 files changed, 36 insertions, 36 deletions
diff --git a/hash.h b/hash.h
index d98a8144ed85b..a05a9f4f47325 100644
--- a/hash.h
+++ b/hash.h
@@ -1,4 +1,4 @@
-/* $NetBSD: hash.h,v 1.21 2020/09/01 21:11:31 rillig Exp $ */
+/* $NetBSD: hash.h,v 1.31 2020/10/25 19:19:07 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -78,54 +78,54 @@
#define MAKE_HASH_H
/* A single key-value entry in the hash table. */
-typedef struct Hash_Entry {
- struct Hash_Entry *next; /* Used to link together all the entries
+typedef struct HashEntry {
+ struct HashEntry *next; /* Used to link together all the entries
* associated with the same bucket. */
- void *value;
- unsigned namehash; /* hash value of key */
- char name[1]; /* key string, variable length */
-} Hash_Entry;
+ void *value;
+ unsigned int key_hash; /* hash value of the key */
+ char key[1]; /* key string, variable length */
+} HashEntry;
/* The hash table containing the entries. */
-typedef struct Hash_Table {
- Hash_Entry **buckets; /* Pointers to Hash_Entry, one
+typedef struct HashTable {
+ HashEntry **buckets; /* Pointers to HashEntry, one
* for each bucket in the table. */
- int bucketsSize;
- int numEntries; /* Number of entries in the table. */
- int bucketsMask; /* Used to select the bucket for a hash. */
- int maxchain; /* max length of chain detected */
-} Hash_Table;
+ unsigned int bucketsSize;
+ unsigned int numEntries; /* Number of entries in the table. */
+ unsigned int bucketsMask; /* Used to select the bucket for a hash. */
+ unsigned int maxchain; /* max length of chain detected */
+} HashTable;
-/*
- * The following structure is used by the searching routines
- * to record where we are in the search.
- */
-typedef struct Hash_Search {
- Hash_Table *table; /* Table being searched. */
- int nextBucket; /* Next bucket to check (after current). */
- Hash_Entry *entry; /* Next entry to check in current bucket. */
-} Hash_Search;
+/* State of an iteration over all entries in a table. */
+typedef struct HashIter {
+ HashTable *table; /* Table being searched. */
+ unsigned int nextBucket; /* Next bucket to check (after current). */
+ HashEntry *entry; /* Next entry to check in current bucket. */
+} HashIter;
-static inline void * MAKE_ATTR_UNUSED
-Hash_GetValue(Hash_Entry *h)
+static inline MAKE_ATTR_UNUSED void *
+HashEntry_Get(HashEntry *h)
{
return h->value;
}
-static inline void MAKE_ATTR_UNUSED
-Hash_SetValue(Hash_Entry *h, void *datum)
+static inline MAKE_ATTR_UNUSED void
+HashEntry_Set(HashEntry *h, void *datum)
{
h->value = datum;
}
-void Hash_InitTable(Hash_Table *, int);
-void Hash_DeleteTable(Hash_Table *);
-Hash_Entry *Hash_FindEntry(Hash_Table *, const char *);
-Hash_Entry *Hash_CreateEntry(Hash_Table *, const char *, Boolean *);
-void Hash_DeleteEntry(Hash_Table *, Hash_Entry *);
-Hash_Entry *Hash_EnumFirst(Hash_Table *, Hash_Search *);
-Hash_Entry *Hash_EnumNext(Hash_Search *);
-void Hash_ForEach(Hash_Table *, void (*)(void *, void *), void *);
-void Hash_DebugStats(Hash_Table *, const char *);
+void HashTable_Init(HashTable *);
+void HashTable_Done(HashTable *);
+HashEntry *HashTable_FindEntry(HashTable *, const char *);
+void *HashTable_FindValue(HashTable *, const char *);
+unsigned int Hash_Hash(const char *);
+void *HashTable_FindValueHash(HashTable *, const char *, unsigned int);
+HashEntry *HashTable_CreateEntry(HashTable *, const char *, Boolean *);
+void HashTable_DeleteEntry(HashTable *, HashEntry *);
+void HashTable_DebugStats(HashTable *, const char *);
+
+void HashIter_Init(HashIter *, HashTable *);
+HashEntry *HashIter_Next(HashIter *);
#endif /* MAKE_HASH_H */