Overview
Comment: | Add -[reduceUsingBlock:] to OFArray. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
03e89edb4282f559f8ce2e8531278ce1 |
User & Date: | js on 2011-07-21 22:01:32 |
Other Links: | manifest | tags |
Context
2011-07-21
| ||
23:56 | Add -[enumerateObjectsUsingBlock:] and -[filteredSetUsingBlock:]. check-in: 3e6766ac10 user: js tags: trunk | |
22:01 | Add -[reduceUsingBlock:] to OFArray. check-in: 03e89edb42 user: js tags: trunk | |
19:52 | Add -[unionSet:] to OFMutableSet. check-in: 05c71bf58b user: js tags: trunk | |
Changes
Modified src/OFArray.h from [43f23f91db] to [a35efcabab].
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | @class OFString; #ifdef OF_HAVE_BLOCKS typedef void (^of_array_enumeration_block_t)(id object, size_t index, BOOL *stop); typedef BOOL (^of_array_filter_block_t)(id odject, size_t index); typedef id (^of_array_map_block_t)(id object, size_t index); #endif /** * \brief A class for storing objects in an array. */ @interface OFArray: OFObject <OFCopying, OFMutableCopying, OFCollection, OFSerialization> | > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | @class OFString; #ifdef OF_HAVE_BLOCKS typedef void (^of_array_enumeration_block_t)(id object, size_t index, BOOL *stop); typedef BOOL (^of_array_filter_block_t)(id odject, size_t index); typedef id (^of_array_map_block_t)(id object, size_t index); typedef id (^of_array_reduce_block_t)(id object1, id object2); #endif /** * \brief A class for storing objects in an array. */ @interface OFArray: OFObject <OFCopying, OFMutableCopying, OFCollection, OFSerialization> |
︙ | ︙ | |||
278 279 280 281 282 283 284 285 286 287 288 289 290 291 | * returns YES. * * \param block A block which determines if the object should be in the new * array * \return A new, autoreleased OFArray */ - (OFArray*)filteredArrayUsingBlock: (of_array_filter_block_t)block; #endif @end @interface OFArrayEnumerator: OFEnumerator { OFArray *array; OFDataArray *dataArray; | > > > > > > > > > > > > > > > > > > | 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | * returns YES. * * \param block A block which determines if the object should be in the new * array * \return A new, autoreleased OFArray */ - (OFArray*)filteredArrayUsingBlock: (of_array_filter_block_t)block; /** * \brief Reduces the array to a single object using the specified block. * * If the array is empty, it will return nil. * * If there is only one object in the array, that object will be returned and * the block will not be invoked. * * If there are at least two objects, the block is invoked for each object * except the first, where object1 is always to what the array has already been * reduced and object2 what should be added to object1. * * \param block A block which reduces two objects into one, which is called for * all objects except the first * \return The array reduced to a single object */ - (id)reduceUsingBlock: (of_array_reduce_block_t)block; #endif @end @interface OFArrayEnumerator: OFEnumerator { OFArray *array; OFDataArray *dataArray; |
︙ | ︙ |
Modified src/OFArray.m from [d4b4c05d50] to [fa2031559e].
︙ | ︙ | |||
650 651 652 653 654 655 656 657 658 659 660 661 662 663 | length: j]; } @finally { [self freeMemory: tmp]; } return ret; } #endif - (void)dealloc { id *cArray = [array cArray]; size_t i, count = [array count]; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 | length: j]; } @finally { [self freeMemory: tmp]; } return ret; } - (id)reduceUsingBlock: (of_array_reduce_block_t)block { OFAutoreleasePool *pool; id *cArray; size_t i, count = [array count]; id current; if (count == 0) return nil; if (count == 1) return [[[self firstObject] retain] autorelease]; cArray = [array cArray]; pool = [[OFAutoreleasePool alloc] init]; current = cArray[0]; for (i = 1; i < count; i++) { id old = current; @try { current = [block(current, cArray[i]) retain]; [pool releaseObjects]; } @finally { [old release]; } } @try { [pool release]; } @catch (id e) { [current release]; @throw e; } return [current autorelease]; } #endif - (void)dealloc { id *cArray = [array cArray]; size_t i, count = [array count]; |
︙ | ︙ |