aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/utils
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-04-06 23:38:30 -0700
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-04-06 23:38:30 -0700
commit86707e3713ecfebdc518406ea0f67767432922c6 (patch)
treee22944544a131c005d8ab24e94f684abd18be622 /src/objc/utils
parent906bc8418a8b0f3b86b24cf017598078fa508206 (diff)
Added index eunumerator to MCOIndexSet.
Diffstat (limited to 'src/objc/utils')
-rw-r--r--src/objc/utils/MCOIndexSet.h3
-rw-r--r--src/objc/utils/MCOIndexSet.mm22
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