OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
hash.h File Reference

Hash tables used to resolve legacy model identifiers. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  HTentry
 

Macros

#define HTMAXSIZE   1999
 
#define NOTFOUND   -1
 

Typedefs

typedef struct HTentry * HTtable
 

Functions

HTtable * HTcreate (void)
 Allocate an empty case-insensitive identifier table.
 
int HTinsert (HTtable *, char *, int)
 Prepend a key/data entry to a hash table without copying its key.
 
int HTfind (HTtable *, const char *)
 Look up the most recently inserted case-insensitive key match.
 
char * HTfindKey (HTtable *, const char *)
 Retrieve the original stored spelling of a case-insensitive key.
 
void HTfree (HTtable *)
 Free all hash entries and the table bucket array.
 

Detailed Description

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)
License
Apache-2.0 for OpenSWMM contributions; original EPA SWMM provenance is retained.

Macro Definition Documentation

◆ HTMAXSIZE

#define HTMAXSIZE   1999

◆ NOTFOUND

#define NOTFOUND   -1

Typedef Documentation

◆ HTtable

typedef struct HTentry* HTtable

Function Documentation

◆ HTcreate()

HTtable * HTcreate ( void )

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]htNon-null borrowed table created by HTcreate().
[in]keyNon-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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ HTfindKey()

char * HTfindKey ( HTtable * ht,
const char * key )

Retrieve the original stored spelling of a case-insensitive key.

Parameters
[in]htNon-null borrowed table created by HTcreate().
[in]keyNon-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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ HTfree()

void HTfree ( HTtable * ht)

Free all hash entries and the table bucket array.

Parameters
[in]htNon-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]htNon-null table created by HTcreate().
[in]keyBorrowed nonempty null-terminated identifier; it must remain alive and unchanged for the entry's lifetime.
[in]dataInteger 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.
Here is the call graph for this function:
Here is the caller graph for this function: