diff options
author | Simon J. Gerraty <sjg@FreeBSD.org> | 2020-09-05 19:29:42 +0000 |
---|---|---|
committer | Simon J. Gerraty <sjg@FreeBSD.org> | 2020-09-05 19:29:42 +0000 |
commit | 2c3632d14fe37fa35c262ee9fb66835be0a52621 (patch) | |
tree | 57d0bb7a1e21c84dc625ee2f42c7677174a79c81 /contrib/bmake/hash.h | |
parent | 08d0b468f14fec9d8d11eea0c7886f53df4eda2e (diff) | |
parent | 6bbc783f48498b808e19db4441299dc7d85a278b (diff) | |
download | src-2c3632d14fe37fa35c262ee9fb66835be0a52621.tar.gz src-2c3632d14fe37fa35c262ee9fb66835be0a52621.zip |
Update to bmake-20200902
Lots of code refactoring, simplification and cleanup.
Lots of new unit-tests providing much higher code coverage.
All courtesy of rillig at netbsd.
Other significant changes:
o new read-only variable .SHELL which provides the path of the shell
used to run scripts (as defined by the .SHELL target).
o variable parsing detects more errors.
o new debug option -dl: LINT mode, does the equivalent of := for all
variable assignments so that file and line number are reported for
variable parse errors.
Notes
Notes:
svn path=/head/; revision=365366
Diffstat (limited to 'contrib/bmake/hash.h')
-rw-r--r-- | contrib/bmake/hash.h | 81 |
1 files changed, 31 insertions, 50 deletions
diff --git a/contrib/bmake/hash.h b/contrib/bmake/hash.h index 2e4ea6a43560..d98a8144ed85 100644 --- a/contrib/bmake/hash.h +++ b/contrib/bmake/hash.h @@ -1,4 +1,4 @@ -/* $NetBSD: hash.h,v 1.13 2020/07/03 17:03:09 rillig Exp $ */ +/* $NetBSD: hash.h,v 1.21 2020/09/01 21:11:31 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -72,71 +72,51 @@ * from: @(#)hash.h 8.1 (Berkeley) 6/6/93 */ -/* hash.h -- - * - * This file contains definitions used by the hash module, - * which maintains hash tables. - */ - -#ifndef _HASH_H -#define _HASH_H +/* Hash tables with strings as keys and arbitrary pointers as values. */ -/* - * The following defines one entry in the hash table. - */ +#ifndef MAKE_HASH_H +#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 associated with the same - * bucket. */ - void *clientPtr; /* Arbitrary pointer */ - unsigned namehash; /* hash value of key */ - char name[1]; /* key string */ + struct Hash_Entry *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; +/* The hash table containing the entries. */ typedef struct Hash_Table { - struct Hash_Entry **bucketPtr;/* Pointers to Hash_Entry, one - * for each bucket in the table. */ - int size; /* Actual size of array. */ + Hash_Entry **buckets; /* Pointers to Hash_Entry, one + * for each bucket in the table. */ + int bucketsSize; int numEntries; /* Number of entries in the table. */ - int mask; /* Used to select bits for hashing. */ + int bucketsMask; /* Used to select the bucket for a hash. */ + int maxchain; /* max length of chain detected */ } Hash_Table; /* * The following structure is used by the searching routines * to record where we are in the search. */ - typedef struct Hash_Search { - Hash_Table *tablePtr; /* Table being searched. */ - int nextIndex; /* Next bucket to check (after current). */ - Hash_Entry *hashEntryPtr; /* Next entry to check in current bucket. */ + 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; -/* - * Macros. - */ - -/* - * void * Hash_GetValue(h) - * Hash_Entry *h; - */ - -#define Hash_GetValue(h) ((h)->clientPtr) - -/* - * Hash_SetValue(h, val); - * Hash_Entry *h; - * char *val; - */ - -#define Hash_SetValue(h, val) ((h)->clientPtr = (val)) - -/* - * Hash_Size(n) returns the number of words in an object of n bytes - */ +static inline void * MAKE_ATTR_UNUSED +Hash_GetValue(Hash_Entry *h) +{ + return h->value; +} -#define Hash_Size(n) (((n) + sizeof (int) - 1) / sizeof (int)) +static inline void MAKE_ATTR_UNUSED +Hash_SetValue(Hash_Entry *h, void *datum) +{ + h->value = datum; +} void Hash_InitTable(Hash_Table *, int); void Hash_DeleteTable(Hash_Table *); @@ -146,5 +126,6 @@ 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 *); -#endif /* _HASH_H */ +#endif /* MAKE_HASH_H */ |