Skip to content

Commit

Permalink
Fixed a major leak in MFDistanceMatrix and its subclass. MFDistanceMa…
Browse files Browse the repository at this point in the history
…trixOperation is now allowed to be cancelled.
  • Loading branch information
4ment committed Nov 27, 2015
1 parent 4c863ce commit 5d03d24
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
10 changes: 5 additions & 5 deletions Seqotron/MFDistanceMatrix.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ -(void)dealloc{
- (float)calculatePairwiseDistanceBetween:(MFSequence*)sequence1 and:(MFSequence*)sequence2{
NSUInteger d = 0;
NSUInteger n = 0;
const char *c1 = [[sequence1 sequence]UTF8String];
const char *c2 = [[sequence2 sequence]UTF8String];
MFDataType *dataType = sequence1.dataType;
NSUInteger dimension = [sequence1 length];

char c1,c2;
for ( NSUInteger k = 0; k < dimension; k++ ) {
if( [dataType isKnownChar:c1[k]] && [dataType isKnownChar:c2[k]] ){
if(c1[k] != c2[k] ){
c1 = [[sequence1 sequence ]characterAtIndex:k];
c2 = [[sequence2 sequence ]characterAtIndex:k];
if( [dataType isKnownChar:c1] && [dataType isKnownChar:c2] ){
if(c1 != c2 ){
d++;
}
n++;
Expand Down
14 changes: 12 additions & 2 deletions Seqotron/MFDistanceMatrixOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,18 @@ -(void)main{
// [self.delegate operation:self setDescription:self.description];
// });
// }

[_matrix calculateDistances];
float **matrix = [_matrix floatMatrix];
NSUInteger dimension = [_sequences count];
for ( NSUInteger i = 0; i < dimension; i++ ) {
MFSequence *seq1 = [_sequences objectAtIndex:i];

for ( NSUInteger j = i+1; j < dimension; j++ ) {
MFSequence *seq2 = [_sequences objectAtIndex:j];
matrix[i][j] = matrix[j][i] = [_matrix calculatePairwiseDistanceBetween:seq1 and:seq2];
}
if( [self isCancelled] )break;
}
//[_matrix calculateDistances];

// [(NSObject *)self.delegate performSelectorOnMainThread: @selector(distanceMatrixDidFinish:)
// withObject: self
Expand Down
10 changes: 5 additions & 5 deletions Seqotron/MFJukeCantorDistanceMatrix.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ @implementation MFJukeCantorDistanceMatrix
- (float)calculatePairwiseDistanceBetween:(MFSequence*)sequence1 and:(MFSequence*)sequence2{
NSUInteger d = 0;
NSUInteger n = 0;
const char *c1 = [[sequence1 sequence]UTF8String];
const char *c2 = [[sequence2 sequence]UTF8String];
MFDataType *dataType = sequence1.dataType;
NSUInteger dimension = [sequence1 length];

char c1,c2;
for ( NSUInteger k = 0; k < dimension; k++ ) {
if( [dataType isKnownChar:c1[k]] && [dataType isKnownChar:c2[k]] ){
if( c1[k] != c2[k] ){
c1 = [[sequence1 sequence ]characterAtIndex:k];
c2 = [[sequence2 sequence ]characterAtIndex:k];
if( [dataType isKnownChar:c1] && [dataType isKnownChar:c2] ){
if( c1 != c2 ){
d++;
}
n++;
Expand Down
10 changes: 5 additions & 5 deletions Seqotron/MFK83DistanceMatrix.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ @implementation MFK83DistanceMatrix
- (float)calculatePairwiseDistanceBetween:(MFSequence*)sequence1 and:(MFSequence*)sequence2{
float d = 0;
NSUInteger n = 0;
const char *c1 = [[sequence1 sequence]UTF8String];
const char *c2 = [[sequence2 sequence]UTF8String];
MFDataType *dataType = sequence1.dataType;
NSUInteger dimension = [sequence1 length];

char c1,c2;
for ( NSUInteger k = 0; k < dimension; k++ ) {
if( [dataType isKnownChar:c1[k]] && [dataType isKnownChar:c2[k]] ){
if( c1[k] != c2[k] ){
c1 = [[sequence1 sequence ]characterAtIndex:k];
c2 = [[sequence2 sequence ]characterAtIndex:k];
if( [dataType isKnownChar:c1] && [dataType isKnownChar:c2] ){
if( c1 != c2 ){
d++;
}
n++;
Expand Down

0 comments on commit 5d03d24

Please sign in to comment.