Fixed destructor to free all items properly
authorDavid Anderson <dvander@alliedmods.net>
Mon Sep 26 16:05:07 2005 +0000 (2005-09-26)
changeset 1156d0d182ef25c
parent 114 6dcc66e9c3cc
child 116 65ce756bf3cc
Fixed destructor to free all items properly
sourcehook/sh_tinyhash.h
sourcehook/test/test.vcproj
     1.1 --- a/sourcehook/sh_tinyhash.h	Sat Sep 24 21:10:53 2005 +0000
     1.2 +++ b/sourcehook/sh_tinyhash.h	Mon Sep 26 16:05:07 2005 +0000
     1.3 @@ -63,17 +63,11 @@
     1.4  
     1.5  		~THash()
     1.6  		{
     1.7 -			if (m_Buckets)
     1.8 -				delete [] m_Buckets;
     1.9 +			_Clear();
    1.10  		}
    1.11  		void clear()
    1.12  		{
    1.13 -			if (m_Buckets)
    1.14 -				delete [] m_Buckets;
    1.15 -			m_Buckets = NULL;
    1.16 -			m_numBuckets = 0;
    1.17 -			m_percentUsed = 0.0f;
    1.18 -			
    1.19 +			_Clear();
    1.20  			_Refactor();
    1.21  		}
    1.22  		size_t GetBuckets()
    1.23 @@ -90,6 +84,21 @@
    1.24  			return pNode->val;
    1.25  		}
    1.26  	private:
    1.27 +		void _Clear()
    1.28 +		{
    1.29 +			for (size_t i=0; i<m_numBuckets; i++)
    1.30 +			{
    1.31 +				if (m_Buckets[i])
    1.32 +				{
    1.33 +					delete m_Buckets[i];
    1.34 +					m_Buckets[i] = NULL;
    1.35 +				}
    1.36 +			}
    1.37 +			if (m_Buckets)
    1.38 +				delete [] m_Buckets;
    1.39 +			m_Buckets = NULL;
    1.40 +			m_numBuckets = 0;
    1.41 +		}
    1.42  		THashNode *_FindOrInsert(const K & key)
    1.43  		{
    1.44  			size_t place = HashFunction(key) % m_numBuckets;
     2.1 --- a/sourcehook/test/test.vcproj	Sat Sep 24 21:10:53 2005 +0000
     2.2 +++ b/sourcehook/test/test.vcproj	Mon Sep 26 16:05:07 2005 +0000
     2.3 @@ -4,6 +4,7 @@
     2.4  	Version="7.10"
     2.5  	Name="test"
     2.6  	ProjectGUID="{456BBA64-FF14-4292-8443-3BA79E4D84CC}"
     2.7 +	RootNamespace="test"
     2.8  	Keyword="Win32Proj">
     2.9  	<Platforms>
    2.10  		<Platform
    2.11 @@ -264,6 +265,9 @@
    2.12  			<File
    2.13  				RelativePath=".\testbail2.cpp">
    2.14  			</File>
    2.15 +			<File
    2.16 +				RelativePath=".\testlist.cpp">
    2.17 +			</File>
    2.18  		</Filter>
    2.19  		<Filter
    2.20  			Name="Header Files"