mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 08:26:27 +00:00
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3019 72102866-910b-0410-8b05-ffd578937521
62 lines
1.3 KiB
Objective-C
62 lines
1.3 KiB
Objective-C
#include <stdio.h>
|
|
#include <Foundation/NSHashTable.h>
|
|
#include <Foundation/NSValue.h>
|
|
#include <Foundation/NSAutoreleasePool.h>
|
|
|
|
int main ()
|
|
{
|
|
NSHashTable *ht;
|
|
NSHashEnumerator he;
|
|
int i;
|
|
void *v;
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
|
|
|
/* Test with ints */
|
|
|
|
ht = NSCreateHashTable (NSIntHashCallBacks, 0);
|
|
|
|
for (i = 1; i < 16; i++)
|
|
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
|
|
|
|
[arp release];
|
|
exit (0);
|
|
}
|