Skip to content

Commit

Permalink
Modified the binary search insertions for the filteredBuffer
Browse files Browse the repository at this point in the history
- Buffer can now hold both CSLReaderBarcode or CSLBleTag object and insertion will be based on EPC or barcodeValue of the objects respectively.
  • Loading branch information
ksclam committed May 12, 2022
1 parent f11ecc6 commit 559daee
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions CS108iOSClient/CSLReader/CSLBleReader.m
Original file line number Diff line number Diff line change
Expand Up @@ -3334,20 +3334,20 @@ - (void)decodePacketsInBufferAsync;
NSUInteger findIndex = [filteredBuffer indexOfObject:tag
inSortedRange:searchRange
options:NSBinarySearchingInsertionIndex | NSBinarySearchingFirstEqual
usingComparator:^(id obj1, id obj2)
{
NSString* str1=((CSLBleTag*)obj1).EPC;
NSString* str2=((CSLBleTag*)obj2).EPC;
return [str1 compare:str2 options:NSCaseInsensitiveSearch];
}];
usingComparator:^(id obj1, id obj2) {
NSString* str1; NSString* str2;
str1 = ([obj1 isKindOfClass:[CSLReaderBarcode class]]) ? ((CSLReaderBarcode*)obj1).barcodeValue : ((CSLBleTag*)obj1).EPC;
str2 = ([obj2 isKindOfClass:[CSLReaderBarcode class]]) ? ((CSLReaderBarcode*)obj2).barcodeValue : ((CSLBleTag*)obj2).EPC;
return [str1 compare:str2 options:NSCaseInsensitiveSearch];
}];

if ( findIndex >= [filteredBuffer count] ) //tag to be the largest. Append to the end.
{
[filteredBuffer insertObject:tag atIndex:findIndex];
uniqueTagCount++;

}
else if ( [((CSLBleTag*)filteredBuffer[findIndex]).EPC caseInsensitiveCompare:tag.EPC] != NSOrderedSame)
else if ( [[filteredBuffer[findIndex] isKindOfClass:[CSLReaderBarcode class]] ? ((CSLReaderBarcode*)filteredBuffer[findIndex]).barcodeValue : ((CSLBleTag*)filteredBuffer[findIndex]).EPC caseInsensitiveCompare:tag.EPC] != NSOrderedSame)
{
//new tag found. insert into buffer in sorted order
[filteredBuffer insertObject:tag atIndex:findIndex];
Expand Down Expand Up @@ -3470,20 +3470,19 @@ - (void)decodePacketsInBufferAsync;
NSUInteger findIndex = [filteredBuffer indexOfObject:tag
inSortedRange:searchRange
options:NSBinarySearchingInsertionIndex | NSBinarySearchingFirstEqual
usingComparator:^(id obj1, id obj2)
{
NSString* str1=((CSLBleTag*)obj1).EPC;
NSString* str2=((CSLBleTag*)obj2).EPC;
return [str1 compare:str2 options:NSCaseInsensitiveSearch];
}];
usingComparator:^(id obj1, id obj2) {
NSString* str1; NSString* str2;
str1 = ([obj1 isKindOfClass:[CSLReaderBarcode class]]) ? ((CSLReaderBarcode*)obj1).barcodeValue : ((CSLBleTag*)obj1).EPC;
str2 = ([obj2 isKindOfClass:[CSLReaderBarcode class]]) ? ((CSLReaderBarcode*)obj2).barcodeValue : ((CSLBleTag*)obj2).EPC;
return [str1 compare:str2 options:NSCaseInsensitiveSearch];
}];

if ( findIndex >= [filteredBuffer count] ) //tag to be the largest. Append to the end.
{
[filteredBuffer insertObject:tag atIndex:findIndex];
uniqueTagCount++;

}
else if ( [((CSLBleTag*)filteredBuffer[findIndex]).EPC caseInsensitiveCompare:tag.EPC] != NSOrderedSame)
else if ( [[filteredBuffer[findIndex] isKindOfClass:[CSLReaderBarcode class]] ? ((CSLReaderBarcode*)filteredBuffer[findIndex]).barcodeValue : ((CSLBleTag*)filteredBuffer[findIndex]).EPC caseInsensitiveCompare:tag.EPC] != NSOrderedSame)
{
//new tag found. insert into buffer in sorted order
[filteredBuffer insertObject:tag atIndex:findIndex];
Expand Down Expand Up @@ -3675,16 +3674,16 @@ - (void)decodePacketsInBufferAsync;
NSUInteger findIndex = [filteredBuffer indexOfObject:barcode
inSortedRange:searchRange
options:NSBinarySearchingInsertionIndex | NSBinarySearchingFirstEqual
usingComparator:^(id obj1, id obj2)
{
NSString* str1=((CSLReaderBarcode*)obj1).barcodeValue;
NSString* str2=((CSLReaderBarcode*)obj2).barcodeValue;
return [str1 compare:str2 options:NSCaseInsensitiveSearch];
}];
usingComparator:^(id obj1, id obj2) {
NSString* str1; NSString* str2;
str1 = ([obj1 isKindOfClass:[CSLReaderBarcode class]]) ? ((CSLReaderBarcode*)obj1).barcodeValue : ((CSLBleTag*)obj1).EPC;
str2 = ([obj2 isKindOfClass:[CSLReaderBarcode class]]) ? ((CSLReaderBarcode*)obj2).barcodeValue : ((CSLBleTag*)obj2).EPC;
return [str1 compare:str2 options:NSCaseInsensitiveSearch];
}];

if ( findIndex >= [filteredBuffer count] ) //tag to be the largest. Append to the end.
[filteredBuffer insertObject:barcode atIndex:findIndex];
else if ( [((CSLReaderBarcode*)filteredBuffer[findIndex]).barcodeValue caseInsensitiveCompare:barcode.barcodeValue] != NSOrderedSame)
else if ( [[filteredBuffer[findIndex] isKindOfClass:[CSLReaderBarcode class]] ? ((CSLReaderBarcode*)filteredBuffer[findIndex]).barcodeValue : ((CSLBleTag*)filteredBuffer[findIndex]).EPC caseInsensitiveCompare:barcode.barcodeValue] != NSOrderedSame)
//new tag found. insert into buffer in sorted order
[filteredBuffer insertObject:barcode atIndex:findIndex];
else //tag is duplicated, but will replace the existing tag information with the new one for updating the RRSI value.
Expand Down

0 comments on commit 559daee

Please sign in to comment.