| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
From: Shawn Erickson
On Thursday, March 28, 2002, at 12:24 PM, Al Guerra wrote:
1. Why is OSArray a member of OSSet instead of its superclass? Is there
some advantage to this in the subset of C++ used?
Both OSArray and OSSet decend from OSCollection (not that OSCollection
does much). OSArray allows index based access to members and will grow
as needed. OSSet doesn't allow index based access, it is intended to act
as an unordered set of unique objects.
With that in mind it doesn't make much sense for it to inherit from
OSArray since it doesn't act like one. The fact that it currently uses
an OSArray internally as its data store is unrelated (for large sets
using an array doesn't make much sense either so keep that in mind when
using OSSet).
It does make sense. That is the point of inheritance: to reuse existing code and reduce space and time requirements with one's parent's methods rather than accessing data as a client.
For example, OSSet's methods withCapacity() and initWithCapacity() before and after reclassifying it as a subclass of OSArray:
Is it just me or does it appear to
add the array from the other set and not its members. I think it should
be calling merge(set->members) not setObject(set->members).
It sure looks that way to me. OSSet::merge(OSSet *) calls OSSet::setObject(OSMetaClassBase *) passing the OSArray set->members which would incorporate the array (but not the set which owns it, which will make for leaks when the set is freed.) It's a nice, indirect way to create a tree, though.
It does seem a little strange to me as well... as coded it will return
true if any but not all members were merged.
Correct. If it were able to successfully add a single element, but failed to grow to add any more it would still return true.
| References: | |
| >Re: Questions about implementations of OSSet and OSArray (From: "Alfonso Guerra" <email@hidden>) |
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.