1995-05-05 18:27:56 +00:00
|
|
|
#include <Foundation/NSDictionary.h>
|
|
|
|
#include <Foundation/NSString.h>
|
|
|
|
#include <Foundation/NSArray.h>
|
1998-10-03 04:46:13 +00:00
|
|
|
#include <Foundation/NSValue.h>
|
|
|
|
#include <Foundation/NSDate.h>
|
|
|
|
#include <Foundation/NSAutoreleasePool.h>
|
2002-01-03 20:39:12 +00:00
|
|
|
#include <assert.h>
|
1995-05-05 18:27:56 +00:00
|
|
|
|
|
|
|
int
|
1998-10-03 04:46:13 +00:00
|
|
|
main(int argc, char** argv, char** envp)
|
1995-05-05 18:27:56 +00:00
|
|
|
{
|
1998-10-03 04:46:13 +00:00
|
|
|
NSString *strs[100000];
|
|
|
|
NSMutableDictionary *dict;
|
|
|
|
NSDate *when;
|
|
|
|
int i, j;
|
|
|
|
NSAutoreleasePool *arp;
|
1995-05-05 18:27:56 +00:00
|
|
|
id a, b; /* dictionaries */
|
|
|
|
id enumerator;
|
|
|
|
id objects, keys;
|
|
|
|
id key;
|
1997-10-16 23:56:27 +00:00
|
|
|
BOOL ok;
|
1998-10-03 04:46:13 +00:00
|
|
|
id o1, o2, o3, o4, o5, o6;
|
|
|
|
NSMutableDictionary *d1, *d2;
|
|
|
|
|
|
|
|
arp = [NSAutoreleasePool new];
|
|
|
|
|
|
|
|
o1 = [[NSNumber numberWithInt:1] stringValue];
|
|
|
|
o2 = [[NSNumber numberWithInt:2] stringValue];
|
|
|
|
o3 = [[NSNumber numberWithInt:3] stringValue];
|
|
|
|
o4 = [[NSNumber numberWithInt:4] stringValue];
|
|
|
|
o5 = [[NSNumber numberWithInt:5] stringValue];
|
|
|
|
o6 = [[NSNumber numberWithInt:6] stringValue];
|
|
|
|
|
|
|
|
d1 = [[NSMutableDictionary new] autorelease];
|
|
|
|
[d1 setObject:o1 forKey:o1];
|
|
|
|
[d1 setObject:o2 forKey:o2];
|
|
|
|
[d1 setObject:o3 forKey:o3];
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1998-10-03 04:46:13 +00:00
|
|
|
d2 = [[NSMutableDictionary new] autorelease];
|
|
|
|
[d2 setObject:o4 forKey:o4];
|
|
|
|
[d2 setObject:o5 forKey:o5];
|
|
|
|
[d2 setObject:o6 forKey:o6];
|
|
|
|
|
|
|
|
[d1 addEntriesFromDictionary: d2];
|
|
|
|
|
|
|
|
enumerator = [d1 objectEnumerator];
|
|
|
|
while ((b = [enumerator nextObject]))
|
|
|
|
printf("%s ", [b cString]);
|
|
|
|
printf("\n");
|
1995-05-05 18:27:56 +00:00
|
|
|
|
2001-04-10 03:27:01 +00:00
|
|
|
//behavior_set_debug(0);
|
1995-05-05 18:27:56 +00:00
|
|
|
|
|
|
|
objects = [NSArray arrayWithObjects:
|
|
|
|
@"vache", @"poisson", @"cheval", @"poulet", nil];
|
|
|
|
keys = [NSArray arrayWithObjects:
|
|
|
|
@"cow", @"fish", @"horse", @"chicken", nil];
|
|
|
|
a = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
|
2003-04-07 08:26:40 +00:00
|
|
|
b = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
@"vache",
|
|
|
|
@"cow",
|
|
|
|
@"poisson",
|
|
|
|
@"fish",
|
|
|
|
@"cheval",
|
|
|
|
@"horse",
|
|
|
|
@"poulet",
|
|
|
|
@"chicken", nil];
|
|
|
|
|
|
|
|
printf("Match is %d\n", [a isEqual: b]);
|
1995-05-05 18:27:56 +00:00
|
|
|
|
|
|
|
printf("NSDictionary has count %d\n", [a count]);
|
|
|
|
key = @"fish";
|
2005-02-22 11:22:44 +00:00
|
|
|
printf("Object at key %s is %s\n",
|
1995-05-05 18:27:56 +00:00
|
|
|
[key cString],
|
|
|
|
[[a objectForKey:key] cString]);
|
|
|
|
|
|
|
|
assert([a count] == [[a allValues] count]);
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1995-05-05 18:27:56 +00:00
|
|
|
enumerator = [a objectEnumerator];
|
|
|
|
while ((b = [enumerator nextObject]))
|
|
|
|
printf("%s ", [b cString]);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
enumerator = [a keyEnumerator];
|
|
|
|
while ((b = [enumerator nextObject]))
|
|
|
|
printf("%s ", [b cString]);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
b = [a mutableCopy];
|
|
|
|
assert([b count]);
|
1997-10-16 23:56:27 +00:00
|
|
|
|
|
|
|
ok = [b isEqual: a];
|
|
|
|
assert(ok);
|
|
|
|
|
1995-05-05 18:27:56 +00:00
|
|
|
[b setObject:@"formi" forKey:@"ant"];
|
|
|
|
[b removeObjectForKey:@"horse"];
|
|
|
|
|
1998-10-03 04:46:13 +00:00
|
|
|
|
|
|
|
when = [NSDate date];
|
|
|
|
dict = [NSMutableDictionary dictionaryWithCapacity: 100];
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
strs[i] = [NSString stringWithFormat: @"Dictkey-%d", i];
|
|
|
|
[dict setObject: strs[i] forKey: strs[i]];
|
|
|
|
}
|
|
|
|
printf(" 10 creation: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
|
|
|
printf("%s\n", [[[dict allKeys] description] cString]);
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1998-10-03 04:46:13 +00:00
|
|
|
when = [NSDate date];
|
|
|
|
for (i = 0; i < 100000; i++) {
|
|
|
|
for (j = 0; j < 10; j++) {
|
|
|
|
NSString *val = [dict objectForKey: strs[j]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf(" 10 For: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
|
|
|
[arp release];
|
|
|
|
|
|
|
|
arp = [NSAutoreleasePool new];
|
|
|
|
|
|
|
|
when = [NSDate date];
|
|
|
|
dict = [NSMutableDictionary dictionaryWithCapacity: 100];
|
|
|
|
for (i = 0; i < 100; i++)
|
|
|
|
{
|
|
|
|
strs[i] = [NSString stringWithFormat: @"Dictkey-%d", i];
|
|
|
|
[dict setObject: strs[i] forKey: strs[i]];
|
|
|
|
}
|
|
|
|
printf(" 100 creation: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1998-10-03 04:46:13 +00:00
|
|
|
when = [NSDate date];
|
|
|
|
for (i = 0; i < 10000; i++) {
|
|
|
|
for (j = 0; j < 100; j++) {
|
|
|
|
NSString *val = [dict objectForKey: strs[j]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf(" 100 For: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
|
|
|
[arp release];
|
|
|
|
|
|
|
|
arp = [NSAutoreleasePool new];
|
|
|
|
|
|
|
|
when = [NSDate date];
|
|
|
|
dict = [NSMutableDictionary dictionaryWithCapacity: 1000];
|
|
|
|
for (i = 0; i < 1000; i++)
|
|
|
|
{
|
|
|
|
strs[i] = [NSString stringWithFormat: @"Dictkey-%d", i];
|
|
|
|
[dict setObject: strs[i] forKey: strs[i]];
|
|
|
|
}
|
|
|
|
printf(" 1000 creation: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1998-10-03 04:46:13 +00:00
|
|
|
when = [NSDate date];
|
|
|
|
for (i = 0; i < 1000; i++) {
|
|
|
|
for (j = 0; j < 1000; j++) {
|
|
|
|
NSString *val = [dict objectForKey: strs[j]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf(" 1000 For: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
|
|
|
[arp release];
|
|
|
|
|
|
|
|
arp = [NSAutoreleasePool new];
|
|
|
|
|
|
|
|
when = [NSDate date];
|
|
|
|
dict = [NSMutableDictionary dictionaryWithCapacity: 10000];
|
|
|
|
for (i = 0; i < 10000; i++)
|
|
|
|
{
|
|
|
|
strs[i] = [NSString stringWithFormat: @"Dictkey-%d", i];
|
|
|
|
[dict setObject: strs[i] forKey: strs[i]];
|
|
|
|
}
|
|
|
|
printf(" 10000 creation: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1998-10-03 04:46:13 +00:00
|
|
|
when = [NSDate date];
|
|
|
|
for (i = 0; i < 100; i++) {
|
|
|
|
for (j = 0; j < 10000; j++) {
|
|
|
|
NSString *val = [dict objectForKey: strs[j]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf(" 10000 For: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
|
|
|
[arp release];
|
|
|
|
|
|
|
|
arp = [NSAutoreleasePool new];
|
|
|
|
|
|
|
|
when = [NSDate date];
|
|
|
|
dict = [NSMutableDictionary dictionaryWithCapacity: 100000];
|
|
|
|
for (i = 0; i < 100000; i++)
|
|
|
|
{
|
|
|
|
strs[i] = [NSString stringWithFormat: @"Dictkey-%d", i];
|
|
|
|
[dict setObject: strs[i] forKey: strs[i]];
|
|
|
|
}
|
|
|
|
printf("100000 creation: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1998-10-03 04:46:13 +00:00
|
|
|
when = [NSDate date];
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
for (j = 0; j < 100000; j++) {
|
|
|
|
NSString *val = [dict objectForKey: strs[j]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("100000 For: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
|
|
|
|
1995-05-05 18:27:56 +00:00
|
|
|
exit(0);
|
|
|
|
}
|