Hash tables used to resolve legacy model identifiers.
More...
#include <stdlib.h>
#include <string.h>
#include "hash.h"
|
| int | samestr (const char *s1, const char *s2) |
| | Compare two nonempty ASCII identifiers without case sensitivity.
|
| |
| unsigned int | hash (const char *str) |
| | Map an ASCII identifier to a case-insensitive Fletcher-checksum bucket.
|
| |
| HTtable * | HTcreate () |
| | Allocate an empty case-insensitive identifier table.
|
| |
| int | HTinsert (HTtable *ht, char *key, int data) |
| | Prepend a key/data entry to a hash table without copying its key.
|
| |
| int | HTfind (HTtable *ht, const char *key) |
| | Look up the most recently inserted case-insensitive key match.
|
| |
| char * | HTfindKey (HTtable *ht, const char *key) |
| | Retrieve the original stored spelling of a case-insensitive key.
|
| |
| void | HTfree (HTtable *ht) |
| | Free all hash entries and the table bucket array.
|
| |
Hash tables used to resolve legacy model identifiers.
- Author
- Caleb Buahin caleb.nosp@m..bua.nosp@m.hin@g.nosp@m.mail.nosp@m..com (OpenSWMM maintenance and extensions)
- Copyright
- Copyright (c) 2026 Caleb Buahin. OpenSWMM contributions only; original EPA SWMM credits are retained.
- License
- Apache-2.0 for OpenSWMM contributions; original EPA SWMM provenance is retained.
◆ UCHAR
Value:(((x) >= 'a' && (x) <= 'z') ? ((x) & ~32) : (x))
◆ hash()
| unsigned int hash |
( |
const char * | str | ) |
|
Map an ASCII identifier to a case-insensitive Fletcher-checksum bucket.
- Parameters
-
| [in] | str | Non-null borrowed null-terminated identifier; empty is permitted. |
- Returns
- Bucket index in [0, HTMAXSIZE - 1]. Input storage is unchanged.
◆ HTcreate()
Allocate an empty case-insensitive identifier table.
- Returns
- Owned zero-initialized HTMAXSIZE bucket array, or NULL on allocation failure.
- Note
- Release the table and its entries with HTfree(); key strings remain externally owned.
◆ HTfind()
| int HTfind |
( |
HTtable * | ht, |
|
|
const char * | key ) |
Look up the most recently inserted case-insensitive key match.
- Parameters
-
| [in] | ht | Non-null borrowed table created by HTcreate(). |
| [in] | key | Non-null borrowed nonempty null-terminated identifier. |
- Returns
- Stored integer value, or NOTFOUND if no entry matches.
- Note
- No storage is modified or retained; returned values can coincide with NOTFOUND if the caller inserted that sentinel as data.
◆ HTfindKey()
| char * HTfindKey |
( |
HTtable * | ht, |
|
|
const char * | key ) |
Retrieve the original stored spelling of a case-insensitive key.
- Parameters
-
| [in] | ht | Non-null borrowed table created by HTcreate(). |
| [in] | key | Non-null borrowed nonempty null-terminated lookup identifier. |
- Returns
- Borrowed original key pointer, or NULL if no entry matches.
- Note
- The pointer's lifetime follows the external key owner; the table does not copy, free or grant mutation rights to the stored identifier.
◆ HTfree()
Free all hash entries and the table bucket array.
- Parameters
-
| [in] | ht | Non-null exclusively owned table created by HTcreate(). |
- Postcondition
- Table and entry pointers are invalid; borrowed key strings are not freed. The caller must discard or reset its own ht pointer after this call.
◆ HTinsert()
| int HTinsert |
( |
HTtable * | ht, |
|
|
char * | key, |
|
|
int | data ) |
Prepend a key/data entry to a hash table without copying its key.
- Parameters
-
| [in,out] | ht | Non-null table created by HTcreate(). |
| [in] | key | Borrowed nonempty null-terminated identifier; it must remain alive and unchanged for the entry's lifetime. |
| [in] | data | Integer value associated with the identifier. |
- Returns
- One on insertion, zero on bucket/allocation failure.
- Note
- Duplicate keys are allowed and newest entries are found first. The table owns the entry allocation, but never frees key storage.
◆ samestr()
| int samestr |
( |
const char * | s1, |
|
|
const char * | s2 ) |
Compare two nonempty ASCII identifiers without case sensitivity.
- Parameters
-
| [in] | s1 | Non-null borrowed null-terminated first string. |
| [in] | s2 | Non-null borrowed null-terminated second string. |
- Returns
- One for equal strings after ASCII case folding, zero otherwise.
- Precondition
- Both identifiers are nonempty; the loop reads one character beyond a matching pair before its termination check. No storage is retained.