@@ -4311,7 +4311,7 @@ - (NSString *)versionTag
4311
4311
/* *
4312
4312
* See header file for extensive documentation for this method.
4313
4313
**/
4314
- - (NSRange )findRangeInGroup : (NSString *)group using : (YapDatabaseViewFind *)find
4314
+ - (NSRange )findRangeInGroup : (NSString *)group using : (YapDatabaseViewFind *)find quitAfterOne : ( BOOL ) quitAfterOne
4315
4315
{
4316
4316
if (group == nil || find == NULL )
4317
4317
{
@@ -4462,6 +4462,11 @@ - (NSRange)findRangeInGroup:(NSString *)group using:(YapDatabaseViewFind *)find
4462
4462
return NSMakeRange (NSNotFound , 0 );
4463
4463
}
4464
4464
4465
+ if (quitAfterOne)
4466
+ {
4467
+ return NSMakeRange (mMid, 1 );
4468
+ }
4469
+
4465
4470
// Find start of range
4466
4471
4467
4472
NSUInteger sMin = mMin;
@@ -4507,6 +4512,14 @@ - (NSRange)findRangeInGroup:(NSString *)group using:(YapDatabaseViewFind *)find
4507
4512
return NSMakeRange (sMin , (eMax - sMin ));
4508
4513
}
4509
4514
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
+
4510
4523
/* *
4511
4524
* This method is deprecated.
4512
4525
* Use findRangeInGroup:using: instead.
@@ -4518,6 +4531,28 @@ - (NSRange)findRangeInGroup:(NSString *)group
4518
4531
return [self findRangeInGroup: group using: [YapDatabaseViewFind withBlock: block blockType: blockType]];
4519
4532
}
4520
4533
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
+
4521
4556
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4522
4557
#pragma mark Public API - Enumerating
4523
4558
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
0 commit comments