1996-02-22 16:14:17 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <Foundation/NSMapTable.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 ()
|
|
|
|
{
|
|
|
|
NSMapTable *mt;
|
|
|
|
NSMapEnumerator me;
|
|
|
|
int i;
|
|
|
|
void *k;
|
|
|
|
void *v;
|
|
|
|
id o;
|
1998-10-03 05:11:05 +00:00
|
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
1996-02-22 16:14:17 +00:00
|
|
|
|
|
|
|
/* Test with ints */
|
|
|
|
|
|
|
|
mt = NSCreateMapTable (NSIntMapKeyCallBacks,
|
|
|
|
NSIntMapValueCallBacks,
|
|
|
|
0);
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
NSMapInsert (mt, (void*)i, (void*)(i*2));
|
|
|
|
|
|
|
|
printf ("value for key %d is %d\n",
|
|
|
|
3, (int)NSMapGet (mt, (void*)3));
|
|
|
|
NSMapRemove (mt, (void*)3);
|
|
|
|
printf ("after removing: value for key %d is %d\n",
|
|
|
|
3, (int)NSMapGet (mt, (void*)3));
|
|
|
|
|
|
|
|
me = NSEnumerateMapTable (mt);
|
|
|
|
while (NSNextMapEnumeratorPair (&me, &k, &v))
|
|
|
|
printf ("(%d,%d) ", (int)k, (int)v);
|
|
|
|
printf ("\n");
|
|
|
|
|
|
|
|
NSFreeMapTable (mt);
|
|
|
|
|
|
|
|
|
|
|
|
/* Test with NSNumber objects */
|
|
|
|
|
|
|
|
mt = NSCreateMapTable (NSObjectMapKeyCallBacks,
|
|
|
|
NSObjectMapValueCallBacks,
|
|
|
|
0);
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
2005-02-22 11:22:44 +00:00
|
|
|
NSMapInsert (mt,
|
|
|
|
[NSNumber numberWithInt: i],
|
1996-02-22 16:14:17 +00:00
|
|
|
[NSNumber numberWithInt: i*i]);
|
|
|
|
|
|
|
|
o = [NSNumber numberWithInt: 3];
|
|
|
|
printf ("value for key %s is %s\n",
|
|
|
|
[[o description] cString],
|
|
|
|
[[(id)NSMapGet (mt, o) description] cString]);
|
|
|
|
NSMapRemove (mt, o);
|
1996-07-15 18:41:44 +00:00
|
|
|
if (NSMapGet (mt, o))
|
|
|
|
printf ("after removing: value for key %s is %s\n",
|
|
|
|
[[o description] cString],
|
|
|
|
[[(id)NSMapGet (mt, o) description] cString]);
|
|
|
|
else
|
|
|
|
printf ("after removing: no value for key %s\n",
|
|
|
|
[[o description] cString]);
|
1996-02-22 16:14:17 +00:00
|
|
|
|
|
|
|
me = NSEnumerateMapTable (mt);
|
|
|
|
while (NSNextMapEnumeratorPair (&me, &k, &v))
|
|
|
|
printf ("(%d,%d) ", [(id)k intValue], [(id)v intValue]);
|
|
|
|
printf ("\n");
|
|
|
|
|
|
|
|
NSFreeMapTable (mt);
|
|
|
|
|
1998-10-03 05:11:05 +00:00
|
|
|
[arp release];
|
1996-02-22 16:14:17 +00:00
|
|
|
exit (0);
|
|
|
|
}
|