diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /utils/shadercompile/utlnodehash.h | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'utils/shadercompile/utlnodehash.h')
| -rw-r--r-- | utils/shadercompile/utlnodehash.h | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/utils/shadercompile/utlnodehash.h b/utils/shadercompile/utlnodehash.h new file mode 100644 index 0000000..0e59a0b --- /dev/null +++ b/utils/shadercompile/utlnodehash.h @@ -0,0 +1,93 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: hashed intrusive linked list. +// +// $NoKeywords: $ +// +// Serialization/unserialization buffer +//=============================================================================// + +#ifndef UTLNODEHASH_H +#define UTLNODEHASH_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "tier1/utlmemory.h" +#include "tier1/byteswap.h" +#include "tier1/utlintrusivelist.h" + +#include <stdarg.h> + +// to use this class, your list node class must have a Key() function defined which returns an +// integer type. May add this class to main utl tier when i'm happy w/ it. +template<class T, int HASHSIZE = 7907, class K = int > class CUtlNodeHash +{ + + int m_nNumNodes; + +public: + + CUtlIntrusiveDList<T> m_HashChains[HASHSIZE]; + + CUtlNodeHash( void ) + { + m_nNumNodes = 0; + } + + + T *FindByKey(K nMatchKey, int *pChainNumber = NULL) + { + unsigned int nChain=(unsigned int) nMatchKey ; + nChain %= HASHSIZE; + if ( pChainNumber ) + *( pChainNumber ) = nChain; + for( T * pNode = m_HashChains[ nChain ].m_pHead; pNode; pNode = pNode->m_pNext ) + if ( pNode->Key() == nMatchKey ) + return pNode; + return NULL; + } + + void Add( T * pNode ) + { + unsigned int nChain=(unsigned int) pNode->Key(); + nChain %= HASHSIZE; + m_HashChains[ nChain ].AddToHead( pNode ); + m_nNumNodes++; + } + + + void Purge( void ) + { + m_nNumNodes = 0; + // delete all nodes + for( int i=0; i < HASHSIZE; i++) + m_HashChains[i].Purge(); + } + + int Count( void ) const + { + return m_nNumNodes; + } + + void DeleteByKey( K nMatchKey ) + { + int nChain; + T *pSearch = FindByKey( nMatchKey, &nChain ); + if ( pSearch ) + { + m_HashChains[ nChain ].RemoveNode( pSearch ); + m_nNumNodes--; + } + } + + ~CUtlNodeHash( void ) + { + // delete all lists + Purge(); + } +}; + + +#endif |