From 86707e3713ecfebdc518406ea0f67767432922c6 Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Sat, 6 Apr 2013 23:38:30 -0700 Subject: Added index eunumerator to MCOIndexSet. --- src/objc/utils/MCOIndexSet.h | 3 +++ src/objc/utils/MCOIndexSet.mm | 22 ++++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/objc/utils/MCOIndexSet.h b/src/objc/utils/MCOIndexSet.h index 5f02935d..1ecf8c9a 100644 --- a/src/objc/utils/MCOIndexSet.h +++ b/src/objc/utils/MCOIndexSet.h @@ -54,6 +54,9 @@ // Returns the number of ranges in this index set. - (unsigned int) rangesCount; +// Enumerates all the indexes of the index set. +- (void) enumerateIndexes:(void (^)(uint64_t idx))block; + @end #endif diff --git a/src/objc/utils/MCOIndexSet.mm b/src/objc/utils/MCOIndexSet.mm index 1827af67..afe9c346 100644 --- a/src/objc/utils/MCOIndexSet.mm +++ b/src/objc/utils/MCOIndexSet.mm @@ -127,19 +127,7 @@ - (MCORange *) allRanges { -#if 0 - NSMutableData * result = [[[NSMutableData alloc] init] autorelease]; - unsigned int count = _indexSet->rangesCount(); - mailcore::Range * mcRanges = _indexSet->allRanges(); - [result setLength:count * sizeof(mailcore::Range)]; - MCORange * ranges = (MCORange *) [result mutableBytes]; - for(unsigned int i = 0 ; i < count ; i ++) { - ranges[i] = MCORangeWithMCRange(mcRanges[i]); - } - return ranges; -#else return (MCORange *) _indexSet->allRanges(); -#endif } - (unsigned int) rangesCount @@ -147,4 +135,14 @@ return _indexSet->rangesCount(); } +- (void) enumerateIndexes:(void (^)(uint64_t idx))block +{ + MCORange * ranges = [self allRanges]; + for(unsigned int i = 0 ; i < [self rangesCount] ; i ++) { + for(uint64_t k = 0 ; k <= ranges[i].length ; k ++) { + block(ranges[i].location + k); + } + } +} + @end -- cgit v1.2.3