summaryrefslogtreecommitdiffstats
path: root/winpr/libwinpr/utils/collections/HashTable.c
blob: 7782b2bf0226bb429e97810cd204341e35c78d8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
/**
 * WinPR: Windows Portable Runtime
 * System.Collections.Hashtable
 *
 * Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <winpr/config.h>

#include <winpr/crt.h>
#include <winpr/assert.h>

#include <winpr/collections.h>

/**
 * This implementation is based on the public domain
 * hash table implementation made by Keith Pomakis:
 *
 * http://www.pomakis.com/hashtable/hashtable.c
 * http://www.pomakis.com/hashtable/hashtable.h
 */

typedef struct s_wKeyValuePair wKeyValuePair;

struct s_wKeyValuePair
{
	void* key;
	void* value;

	wKeyValuePair* next;
	BOOL markedForRemove;
};

struct s_wHashTable
{
	BOOL synchronized;
	CRITICAL_SECTION lock;

	size_t numOfBuckets;
	size_t numOfElements;
	float idealRatio;
	float lowerRehashThreshold;
	float upperRehashThreshold;
	wKeyValuePair** bucketArray;

	HASH_TABLE_HASH_FN hash;
	wObject key;
	wObject value;

	DWORD foreachRecursionLevel;
	DWORD pendingRemoves;
};

BOOL HashTable_PointerCompare(const void* pointer1, const void* pointer2)
{
	return (pointer1 == pointer2);
}

UINT32 HashTable_PointerHash(const void* pointer)
{
	return ((UINT32)(UINT_PTR)pointer) >> 4;
}

BOOL HashTable_StringCompare(const void* string1, const void* string2)
{
	if (!string1 || !string2)
		return (string1 == string2);

	return (strcmp((const char*)string1, (const char*)string2) == 0);
}

UINT32 HashTable_StringHash(const void* key)
{
	UINT32 c = 0;
	UINT32 hash = 5381;
	const BYTE* str = (const BYTE*)key;

	/* djb2 algorithm */
	while ((c = *str++) != '\0')
		hash = (hash * 33) + c;

	return hash;
}

void* HashTable_StringClone(const void* str)
{
	return winpr_ObjectStringClone(str);
}

void HashTable_StringFree(void* str)
{
	winpr_ObjectStringFree(str);
}

static INLINE BOOL HashTable_IsProbablePrime(size_t oddNumber)
{
	for (size_t i = 3; i < 51; i += 2)
	{
		if (oddNumber == i)
			return TRUE;
		else if (oddNumber % i == 0)
			return FALSE;
	}

	return TRUE; /* maybe */
}

static INLINE size_t HashTable_CalculateIdealNumOfBuckets(wHashTable* table)
{
	WINPR_ASSERT(table);

	const float tmp = (table->numOfElements / table->idealRatio);
	size_t idealNumOfBuckets = (size_t)tmp;

	if (idealNumOfBuckets < 5)
		idealNumOfBuckets = 5;
	else
		idealNumOfBuckets |= 0x01;

	while (!HashTable_IsProbablePrime(idealNumOfBuckets))
		idealNumOfBuckets += 2;

	return idealNumOfBuckets;
}

static INLINE void HashTable_Rehash(wHashTable* table, size_t numOfBuckets)
{
	UINT32 hashValue = 0;
	wKeyValuePair* nextPair = NULL;
	wKeyValuePair** newBucketArray = NULL;

	WINPR_ASSERT(table);
	if (numOfBuckets == 0)
		numOfBuckets = HashTable_CalculateIdealNumOfBuckets(table);

	if (numOfBuckets == table->numOfBuckets)
		return; /* already the right size! */

	newBucketArray = (wKeyValuePair**)calloc(numOfBuckets, sizeof(wKeyValuePair*));

	if (!newBucketArray)
	{
		/*
		 * Couldn't allocate memory for the new array.
		 * This isn't a fatal error; we just can't perform the rehash.
		 */
		return;
	}

	for (size_t index = 0; index < table->numOfBuckets; index++)
	{
		wKeyValuePair* pair = table->bucketArray[index];

		while (pair)
		{
			nextPair = pair->next;
			hashValue = table->hash(pair->key) % numOfBuckets;
			pair->next = newBucketArray[hashValue];
			newBucketArray[hashValue] = pair;
			pair = nextPair;
		}
	}

	free(table->bucketArray);
	table->bucketArray = newBucketArray;
	table->numOfBuckets = numOfBuckets;
}

static INLINE BOOL HashTable_Equals(wHashTable* table, const wKeyValuePair* pair, const void* key)
{
	WINPR_ASSERT(table);
	WINPR_ASSERT(pair);
	WINPR_ASSERT(key);
	return table->key.fnObjectEquals(key, pair->key);
}

static INLINE wKeyValuePair* HashTable_Get(wHashTable* table, const void* key)
{
	UINT32 hashValue = 0;
	wKeyValuePair* pair = NULL;

	WINPR_ASSERT(table);
	if (!key)
		return NULL;

	hashValue = table->hash(key) % table->numOfBuckets;
	pair = table->bucketArray[hashValue];

	while (pair && !HashTable_Equals(table, pair, key))
		pair = pair->next;

	return pair;
}

static INLINE void disposeKey(wHashTable* table, void* key)
{
	WINPR_ASSERT(table);
	if (table->key.fnObjectFree)
		table->key.fnObjectFree(key);
}

static INLINE void disposeValue(wHashTable* table, void* value)
{
	WINPR_ASSERT(table);
	if (table->value.fnObjectFree)
		table->value.fnObjectFree(value);
}

static INLINE void disposePair(wHashTable* table, wKeyValuePair* pair)
{
	WINPR_ASSERT(table);
	if (!pair)
		return;
	disposeKey(table, pair->key);
	disposeValue(table, pair->value);
	free(pair);
}

static INLINE void setKey(wHashTable* table, wKeyValuePair* pair, const void* key)
{
	WINPR_ASSERT(table);
	if (!pair)
		return;
	disposeKey(table, pair->key);
	if (table->key.fnObjectNew)
		pair->key = table->key.fnObjectNew(key);
	else
	{
		union
		{
			const void* cpv;
			void* pv;
		} cnv;
		cnv.cpv = key;
		pair->key = cnv.pv;
	}
}

static INLINE void setValue(wHashTable* table, wKeyValuePair* pair, const void* value)
{
	WINPR_ASSERT(table);
	if (!pair)
		return;
	disposeValue(table, pair->value);
	if (table->value.fnObjectNew)
		pair->value = table->value.fnObjectNew(value);
	else
	{
		union
		{
			const void* cpv;
			void* pv;
		} cnv;
		cnv.cpv = value;
		pair->value = cnv.pv;
	}
}

/**
 * C equivalent of the C# Hashtable Class:
 * http://msdn.microsoft.com/en-us/library/system.collections.hashtable.aspx
 */

/**
 * Properties
 */

/**
 * Gets the number of key/value pairs contained in the HashTable.
 */

size_t HashTable_Count(wHashTable* table)
{
	WINPR_ASSERT(table);
	return table->numOfElements;
}

/**
 * Methods
 */

/**
 * Adds an element with the specified key and value into the HashTable.
 */
#if defined(WITH_WINPR_DEPRECATED)
int HashTable_Add(wHashTable* table, const void* key, const void* value)
{
	if (!HashTable_Insert(table, key, value))
		return -1;
	return 0;
}
#endif

BOOL HashTable_Insert(wHashTable* table, const void* key, const void* value)
{
	BOOL rc = FALSE;
	UINT32 hashValue = 0;
	wKeyValuePair* pair = NULL;
	wKeyValuePair* newPair = NULL;

	WINPR_ASSERT(table);
	if (!key || !value)
		return FALSE;

	if (table->synchronized)
		EnterCriticalSection(&table->lock);

	hashValue = table->hash(key) % table->numOfBuckets;
	pair = table->bucketArray[hashValue];

	while (pair && !HashTable_Equals(table, pair, key))
		pair = pair->next;

	if (pair)
	{
		if (pair->markedForRemove)
		{
			/* this entry was set to be removed but will be recycled instead */
			table->pendingRemoves--;
			pair->markedForRemove = FALSE;
			table->numOfElements++;
		}

		if (pair->key != key)
		{
			setKey(table, pair, key);
		}

		if (pair->value != value)
		{
			setValue(table, pair, value);
		}
		rc = TRUE;
	}
	else
	{
		newPair = (wKeyValuePair*)calloc(1, sizeof(wKeyValuePair));

		if (newPair)
		{
			setKey(table, newPair, key);
			setValue(table, newPair, value);
			newPair->next = table->bucketArray[hashValue];
			newPair->markedForRemove = FALSE;
			table->bucketArray[hashValue] = newPair;
			table->numOfElements++;

			if (!table->foreachRecursionLevel && table->upperRehashThreshold > table->idealRatio)
			{
				float elementToBucketRatio =
				    (float)table->numOfElements / (float)table->numOfBuckets;

				if (elementToBucketRatio > table->upperRehashThreshold)
					HashTable_Rehash(table, 0);
			}
			rc = TRUE;
		}
	}

	if (table->synchronized)
		LeaveCriticalSection(&table->lock);

	return rc;
}

/**
 * Removes the element with the specified key from the HashTable.
 */

BOOL HashTable_Remove(wHashTable* table, const void* key)
{
	UINT32 hashValue = 0;
	BOOL status = TRUE;
	wKeyValuePair* pair = NULL;
	wKeyValuePair* previousPair = NULL;

	WINPR_ASSERT(table);
	if (!key)
		return FALSE;

	if (table->synchronized)
		EnterCriticalSection(&table->lock);

	hashValue = table->hash(key) % table->numOfBuckets;
	pair = table->bucketArray[hashValue];

	while (pair && !HashTable_Equals(table, pair, key))
	{
		previousPair = pair;
		pair = pair->next;
	}

	if (!pair)
	{
		status = FALSE;
		goto out;
	}

	if (table->foreachRecursionLevel)
	{
		/* if we are running a HashTable_Foreach, just mark the entry for removal */
		pair->markedForRemove = TRUE;
		table->pendingRemoves++;
		table->numOfElements--;
		goto out;
	}

	if (previousPair)
		previousPair->next = pair->next;
	else
		table->bucketArray[hashValue] = pair->next;

	disposePair(table, pair);
	table->numOfElements--;

	if (!table->foreachRecursionLevel && table->lowerRehashThreshold > 0.0f)
	{
		float elementToBucketRatio = (float)table->numOfElements / (float)table->numOfBuckets;

		if (elementToBucketRatio < table->lowerRehashThreshold)
			HashTable_Rehash(table, 0);
	}

out:
	if (table->synchronized)
		LeaveCriticalSection(&table->lock);

	return status;
}

/**
 * Get an item value using key
 */

void* HashTable_GetItemValue(wHashTable* table, const void* key)
{
	void* value = NULL;
	wKeyValuePair* pair = NULL;

	WINPR_ASSERT(table);
	if (!key)
		return NULL;

	if (table->synchronized)
		EnterCriticalSection(&table->lock);

	pair = HashTable_Get(table, key);

	if (pair && !pair->markedForRemove)
		value = pair->value;

	if (table->synchronized)
		LeaveCriticalSection(&table->lock);

	return value;
}

/**
 * Set an item value using key
 */

BOOL HashTable_SetItemValue(wHashTable* table, const void* key, const void* value)
{
	BOOL status = TRUE;
	wKeyValuePair* pair = NULL;

	WINPR_ASSERT(table);
	if (!key)
		return FALSE;

	if (table->synchronized)
		EnterCriticalSection(&table->lock);

	pair = HashTable_Get(table, key);

	if (!pair || pair->markedForRemove)
		status = FALSE;
	else
	{
		setValue(table, pair, value);
	}

	if (table->synchronized)
		LeaveCriticalSection(&table->lock);

	return status;
}

/**
 * Removes all elements from the HashTable.
 */

void HashTable_Clear(wHashTable* table)
{
	wKeyValuePair* nextPair = NULL;

	WINPR_ASSERT(table);

	if (table->synchronized)
		EnterCriticalSection(&table->lock);

	for (size_t index = 0; index < table->numOfBuckets; index++)
	{
		wKeyValuePair* pair = table->bucketArray[index];

		while (pair)
		{
			nextPair = pair->next;

			if (table->foreachRecursionLevel)
			{
				/* if we're in a foreach we just mark the entry for removal */
				pair->markedForRemove = TRUE;
				table->pendingRemoves++;
			}
			else
			{
				disposePair(table, pair);
				pair = nextPair;
			}
		}

		table->bucketArray[index] = NULL;
	}

	table->numOfElements = 0;
	if (table->foreachRecursionLevel == 0)
		HashTable_Rehash(table, 5);

	if (table->synchronized)
		LeaveCriticalSection(&table->lock);
}

/**
 * Gets the list of keys as an array
 */

size_t HashTable_GetKeys(wHashTable* table, ULONG_PTR** ppKeys)
{
	size_t iKey = 0;
	size_t count = 0;
	ULONG_PTR* pKeys = NULL;
	wKeyValuePair* nextPair = NULL;

	WINPR_ASSERT(table);

	if (table->synchronized)
		EnterCriticalSection(&table->lock);

	iKey = 0;
	count = table->numOfElements;
	*ppKeys = NULL;

	if (count < 1)
	{
		if (table->synchronized)
			LeaveCriticalSection(&table->lock);

		return 0;
	}

	pKeys = (ULONG_PTR*)calloc(count, sizeof(ULONG_PTR));

	if (!pKeys)
	{
		if (table->synchronized)
			LeaveCriticalSection(&table->lock);

		return 0;
	}

	for (size_t index = 0; index < table->numOfBuckets; index++)
	{
		wKeyValuePair* pair = table->bucketArray[index];

		while (pair)
		{
			nextPair = pair->next;
			if (!pair->markedForRemove)
				pKeys[iKey++] = (ULONG_PTR)pair->key;
			pair = nextPair;
		}
	}

	if (table->synchronized)
		LeaveCriticalSection(&table->lock);

	if (ppKeys)
		*ppKeys = pKeys;
	else
		free(pKeys);
	return count;
}

BOOL HashTable_Foreach(wHashTable* table, HASH_TABLE_FOREACH_FN fn, VOID* arg)
{
	BOOL ret = TRUE;

	WINPR_ASSERT(table);
	WINPR_ASSERT(fn);

	if (table->synchronized)
		EnterCriticalSection(&table->lock);

	table->foreachRecursionLevel++;
	for (size_t index = 0; index < table->numOfBuckets; index++)
	{
		for (wKeyValuePair* pair = table->bucketArray[index]; pair; pair = pair->next)
		{
			if (!pair->markedForRemove && !fn(pair->key, pair->value, arg))
			{
				ret = FALSE;
				goto out;
			}
		}
	}
	table->foreachRecursionLevel--;

	if (!table->foreachRecursionLevel && table->pendingRemoves)
	{
		/* if we're the last recursive foreach call, let's do the cleanup if needed */
		wKeyValuePair** prevPtr = NULL;
		for (size_t index = 0; index < table->numOfBuckets; index++)
		{
			wKeyValuePair* nextPair = NULL;
			prevPtr = &table->bucketArray[index];
			for (wKeyValuePair* pair = table->bucketArray[index]; pair;)
			{
				nextPair = pair->next;

				if (pair->markedForRemove)
				{
					disposePair(table, pair);
					*prevPtr = nextPair;
				}
				else
				{
					prevPtr = &pair->next;
				}
				pair = nextPair;
			}
		}
		table->pendingRemoves = 0;
	}

out:
	if (table->synchronized)
		LeaveCriticalSection(&table->lock);
	return ret;
}

/**
 * Determines whether the HashTable contains a specific key.
 */

BOOL HashTable_Contains(wHashTable* table, const void* key)
{
	BOOL status = 0;
	wKeyValuePair* pair = NULL;

	WINPR_ASSERT(table);
	if (!key)
		return FALSE;

	if (table->synchronized)
		EnterCriticalSection(&table->lock);

	pair = HashTable_Get(table, key);
	status = (pair && !pair->markedForRemove);

	if (table->synchronized)
		LeaveCriticalSection(&table->lock);

	return status;
}

/**
 * Determines whether the HashTable contains a specific key.
 */

BOOL HashTable_ContainsKey(wHashTable* table, const void* key)
{
	BOOL status = 0;
	wKeyValuePair* pair = NULL;

	WINPR_ASSERT(table);
	if (!key)
		return FALSE;

	if (table->synchronized)
		EnterCriticalSection(&table->lock);

	pair = HashTable_Get(table, key);
	status = (pair && !pair->markedForRemove);

	if (table->synchronized)
		LeaveCriticalSection(&table->lock);

	return status;
}

/**
 * Determines whether the HashTable contains a specific value.
 */

BOOL HashTable_ContainsValue(wHashTable* table, const void* value)
{
	BOOL status = FALSE;

	WINPR_ASSERT(table);
	if (!value)
		return FALSE;

	if (table->synchronized)
		EnterCriticalSection(&table->lock);

	for (size_t index = 0; index < table->numOfBuckets; index++)
	{
		wKeyValuePair* pair = table->bucketArray[index];

		while (pair)
		{
			if (!pair->markedForRemove && HashTable_Equals(table, pair, value))
			{
				status = TRUE;
				break;
			}

			pair = pair->next;
		}

		if (status)
			break;
	}

	if (table->synchronized)
		LeaveCriticalSection(&table->lock);

	return status;
}

/**
 * Construction, Destruction
 */

wHashTable* HashTable_New(BOOL synchronized)
{
	wHashTable* table = (wHashTable*)calloc(1, sizeof(wHashTable));

	if (!table)
		goto fail;

	table->synchronized = synchronized;
	InitializeCriticalSectionAndSpinCount(&(table->lock), 4000);
	table->numOfBuckets = 64;
	table->numOfElements = 0;
	table->bucketArray = (wKeyValuePair**)calloc(table->numOfBuckets, sizeof(wKeyValuePair*));

	if (!table->bucketArray)
		goto fail;

	table->idealRatio = 3.0;
	table->lowerRehashThreshold = 0.0;
	table->upperRehashThreshold = 15.0;
	table->hash = HashTable_PointerHash;
	table->key.fnObjectEquals = HashTable_PointerCompare;
	table->value.fnObjectEquals = HashTable_PointerCompare;

	return table;
fail:
	WINPR_PRAGMA_DIAG_PUSH
	WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
	HashTable_Free(table);
	WINPR_PRAGMA_DIAG_POP
	return NULL;
}

void HashTable_Free(wHashTable* table)
{
	wKeyValuePair* pair = NULL;
	wKeyValuePair* nextPair = NULL;

	if (!table)
		return;

	if (table->bucketArray)
	{
		for (size_t index = 0; index < table->numOfBuckets; index++)
		{
			pair = table->bucketArray[index];

			while (pair)
			{
				nextPair = pair->next;

				disposePair(table, pair);
				pair = nextPair;
			}
		}
		free(table->bucketArray);
	}
	DeleteCriticalSection(&(table->lock));

	free(table);
}

void HashTable_Lock(wHashTable* table)
{
	WINPR_ASSERT(table);
	EnterCriticalSection(&table->lock);
}

void HashTable_Unlock(wHashTable* table)
{
	WINPR_ASSERT(table);
	LeaveCriticalSection(&table->lock);
}

wObject* HashTable_KeyObject(wHashTable* table)
{
	WINPR_ASSERT(table);
	return &table->key;
}

wObject* HashTable_ValueObject(wHashTable* table)
{
	WINPR_ASSERT(table);
	return &table->value;
}

BOOL HashTable_SetHashFunction(wHashTable* table, HASH_TABLE_HASH_FN fn)
{
	WINPR_ASSERT(table);
	table->hash = fn;
	return fn != NULL;
}

BOOL HashTable_SetupForStringData(wHashTable* table, BOOL stringValues)
{
	wObject* obj = NULL;

	if (!HashTable_SetHashFunction(table, HashTable_StringHash))
		return FALSE;

	obj = HashTable_KeyObject(table);
	obj->fnObjectEquals = HashTable_StringCompare;
	obj->fnObjectNew = HashTable_StringClone;
	obj->fnObjectFree = HashTable_StringFree;

	if (stringValues)
	{
		obj = HashTable_ValueObject(table);
		obj->fnObjectEquals = HashTable_StringCompare;
		obj->fnObjectNew = HashTable_StringClone;
		obj->fnObjectFree = HashTable_StringFree;
	}
	return TRUE;
}