mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-26 02:01:03 +00:00
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3019 72102866-910b-0410-8b05-ffd578937521
72 lines
1.7 KiB
Objective-C
72 lines
1.7 KiB
Objective-C
#include <stdio.h>
|
|
#include <Foundation/NSMapTable.h>
|
|
#include <Foundation/NSValue.h>
|
|
#include <Foundation/NSAutoreleasePool.h>
|
|
|
|
int main ()
|
|
{
|
|
NSMapTable *mt;
|
|
NSMapEnumerator me;
|
|
int i;
|
|
void *k;
|
|
void *v;
|
|
id o;
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
|
|
|
/* 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++)
|
|
NSMapInsert (mt,
|
|
[NSNumber numberWithInt: i],
|
|
[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);
|
|
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]);
|
|
|
|
me = NSEnumerateMapTable (mt);
|
|
while (NSNextMapEnumeratorPair (&me, &k, &v))
|
|
printf ("(%d,%d) ", [(id)k intValue], [(id)v intValue]);
|
|
printf ("\n");
|
|
|
|
NSFreeMapTable (mt);
|
|
|
|
[arp release];
|
|
exit (0);
|
|
}
|