@@ -4311,7 +4311,7 @@ - (NSString *)versionTag
43114311/* *
43124312 * See header file for extensive documentation for this method.
43134313**/
4314- - (NSRange )findRangeInGroup : (NSString *)group using : (YapDatabaseViewFind *)find
4314+ - (NSRange )findRangeInGroup : (NSString *)group using : (YapDatabaseViewFind *)find quitAfterOne : ( BOOL ) quitAfterOne
43154315{
43164316 if (group == nil || find == NULL )
43174317 {
@@ -4462,6 +4462,11 @@ - (NSRange)findRangeInGroup:(NSString *)group using:(YapDatabaseViewFind *)find
44624462 return NSMakeRange (NSNotFound , 0 );
44634463 }
44644464
4465+ if (quitAfterOne)
4466+ {
4467+ return NSMakeRange (mMid, 1 );
4468+ }
4469+
44654470 // Find start of range
44664471
44674472 NSUInteger sMin = mMin;
@@ -4507,6 +4512,14 @@ - (NSRange)findRangeInGroup:(NSString *)group using:(YapDatabaseViewFind *)find
45074512 return NSMakeRange (sMin , (eMax - sMin ));
45084513}
45094514
4515+ /* *
4516+ * See header file for extensive documentation for this method.
4517+ **/
4518+ - (NSRange )findRangeInGroup : (NSString *)group using : (YapDatabaseViewFind *)find
4519+ {
4520+ return [self findRangeInGroup: group using: find quitAfterOne: NO ];
4521+ }
4522+
45104523/* *
45114524 * This method is deprecated.
45124525 * Use findRangeInGroup:using: instead.
@@ -4518,6 +4531,28 @@ - (NSRange)findRangeInGroup:(NSString *)group
45184531 return [self findRangeInGroup: group using: [YapDatabaseViewFind withBlock: block blockType: blockType]];
45194532}
45204533
4534+ /* *
4535+ * This method uses a binary search algorithm to find an item within the view that matches the given criteria.
4536+ *
4537+ * It works similarly to findRangeInGroup:using:, but immediately returns once a single match has been found.
4538+ * This makes it more efficient when you only care about the existence of a match,
4539+ * or you know there will never be more than a single match.
4540+ *
4541+ * See the documentation for findRangeInGroup:using: for more information.
4542+ * @see findRangeInGroup:using:
4543+ *
4544+ * @return
4545+ * If found, the index of the first match discovered.
4546+ * That is, an item where the find block returned NSOrderedSame.
4547+ * If not found, returns NSNotFound.
4548+ **/
4549+ - (NSUInteger )findFirstMatchInGroup : (NSString *)group using : (YapDatabaseViewFind *)find
4550+ {
4551+ NSRange range = [self findRangeInGroup: group using: find quitAfterOne: YES ];
4552+
4553+ return range.location ;
4554+ }
4555+
45214556// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
45224557#pragma mark Public API - Enumerating
45234558// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
0 commit comments