1996-02-22 16:14:17 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <Foundation/NSHashTable.h>
|
|
|
|
#include <Foundation/NSValue.h>
|
1998-10-03 05:11:05 +00:00
|
|
|
#include <Foundation/NSAutoreleasePool.h>
|
1996-02-22 16:14:17 +00:00
|
|
|
|
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
NSHashTable *ht;
|
|
|
|
NSHashEnumerator he;
|
|
|
|
int i;
|
|
|
|
void *v;
|
1998-10-03 05:11:05 +00:00
|
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
1996-02-22 16:14:17 +00:00
|
|
|
|
|
|
|
/* Test with ints */
|
|
|
|
|
|
|
|
ht = NSCreateHashTable (NSIntHashCallBacks, 0);
|
|
|
|
|
1996-10-31 20:51:42 +00:00
|
|
|
for (i = 1; i < 16; i++)
|
1996-02-22 16:14:17 +00:00
|
|
|
NSHashInsert (ht, (void*)i);
|
|
|
|
|
|
|
|
NSHashRemove (ht, (void*)3);
|
|
|
|
|
|
|
|
he = NSEnumerateHashTable (ht);
|
|
|
|
while ((v = NSNextHashEnumeratorItem (&he)))
|
|
|
|
printf ("(%d) ", (int)v);
|
|
|
|
printf ("\n");
|
|
|
|
|
|
|
|
NSFreeHashTable (ht);
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Test with NSNumber objects */
|
|
|
|
|
|
|
|
mt = NSCreateHashTable (NSObjectHashKeyCallBacks,
|
|
|
|
NSObjectHashValueCallBacks,
|
|
|
|
0);
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
NSHashInsert (mt,
|
|
|
|
[NSNumber numberWithInt: i],
|
|
|
|
[NSNumber numberWithInt: i*i]);
|
|
|
|
|
|
|
|
o = [NSNumber numberWithInt: 3];
|
|
|
|
printf ("value for key %s is %s\n",
|
|
|
|
[[o description] cString],
|
|
|
|
[[(id)NSHashGet (mt, o) description] cString]);
|
|
|
|
NSHashRemove (mt, o);
|
|
|
|
printf ("after removing: value for key %s is %s\n",
|
|
|
|
[[o description] cString],
|
|
|
|
[[(id)NSHashGet (mt, o) description] cString]);
|
|
|
|
|
|
|
|
me = NSEnumerateHashTable (mt);
|
|
|
|
while (NSNextHashEnumeratorPair (&me, &k, &v))
|
|
|
|
printf ("(%d,%d) ", [(id)k intValue], [(id)v intValue]);
|
|
|
|
printf ("\n");
|
|
|
|
|
|
|
|
NSFreeHashTable (mt);
|
|
|
|
#endif
|
|
|
|
|
1998-10-03 05:11:05 +00:00
|
|
|
[arp release];
|
1996-02-22 16:14:17 +00:00
|
|
|
exit (0);
|
|
|
|
}
|