//see header file for "how to use" documentation void quickSort(int *array, int n, bool isOrderASC) { //always sort in ascending order quickSort_Internal(array, 0, n-1); //if the specified order is descending, just inverse the array if(!isOrderASC) { inverseArray(array, n); } }
/* ** 从集中器返回帧, 读取集中器号. ** @gatewatId: 集中器号, 从消息中的反序, 变为正序 ** @idLen: 集中器号的长度 ** @buf: 返回帧 ** @bufSize: 返回帧的长度 */ U8 protoA_radioReadId(U8 *gatewayId, U8 idLen, U8* buf, U16 bufSize) { //检查消息合法性 if (protoA_retFrameLen(buf, bufSize) == ERROR) return ERROR; buf += GATEWAY_RETID_OFFSET; memcpy(gatewayId, buf, GATEWAY_OADD_LEN); inverseArray(gatewayId, GATEWAY_OADD_LEN); return NO_ERR; }
/* ** 反序输入的字符串至BCD码. ** @s: 源字符串 ** @sLen: 源字符串长度 ** @t: 目标字符串 ** @tLen: 目标字符串长度 */ U8 inverseStrToBCD(U8* s, U16 sLen, U8* t, U16 tLen) { U16 i = 0; if (sLen % 2) return ERROR; for (i = 0;i < sLen/2;i++, s += 2) {//convert ascii to hex each two chars t[i] = (ASCII_TO_HEX(s[0]) << 4 | ASCII_TO_HEX(s[1])); } inverseArray(t, i); return NO_ERR; }
void getAlignment(int* matrix, char* matsub, int sizeM, short gapVal, short expandGap, char* seq1, int size1, char* seq2, int size2, char** res1, char** res2) { *res2 = (char*) malloc((size1+size2)*sizeof(char)); *res1 = (char*) malloc((size1+size2)*sizeof(char)); int indiceRes = 0; int indiceSeq1 = size1-1; int indiceSeq2 = size2-1; int x, y, tmp; findScorePositionInMatrix(matrix, size1, size2, &x, &y); // viewMatrix(matrix, size1, size2); //printf("position x: %d, y:%d\n", x, y); for(size_t i = x; i < size2; i++) { (*res2)[indiceRes] = seq2[indiceSeq2--]; (*res1)[indiceRes++] = -1; } for(size_t i = y; i < size1; i++) { (*res1)[indiceRes] = seq1[indiceSeq1--]; (*res2)[indiceRes++] = -1; } while(x != 0 && y != 0) { /* printf("Comp %d + %d(%d,%d) == %d \n", matrix[(x-1)*SIZE+y-1], blosumValue(matsub, sizeM, seq1[y-1], seq2[x-1]), seq1[y-1], seq2[x-1], matrix[x*SIZE+y] ); */ if( matrix[(x-1)*SIZE+y-1]+blosumValue(matsub, sizeM, seq1[y-1], seq2[x-1]) == matrix[x*SIZE+y] ) { (*res1)[indiceRes] = seq1[indiceSeq1--]; (*res2)[indiceRes++] = seq2[indiceSeq2--]; x -= 1; y -= 1; } else if( 0 < (tmp=findEndGap(matrix, gapVal, expandGap, x*SIZE+y, 1, x*SIZE)) ) { // printf("Decalage %d\n", tmp); for(int i = 0; i < tmp; i++) { (*res1)[indiceRes] = seq1[indiceSeq1--]; (*res2)[indiceRes++] = -1;// seq2[indiceSeq2--]; y -= 1; } } else if( 0 < (tmp=findEndGap(matrix, gapVal, expandGap, x*SIZE+y, SIZE, 0)) ) { for(int i = 0; i < tmp; i++) { (*res1)[indiceRes] = -1; //seq1[indiceSeq1--]; (*res2)[indiceRes++] = seq2[indiceSeq2--]; x -= 1; } } else exit(0); } for(size_t i = 0; i < x; i++) { (*res2)[indiceRes] = seq2[indiceSeq2--]; (*res1)[indiceRes++] = -1; } for(size_t i = 0; i < y; i++) { (*res1)[indiceRes] = seq1[indiceSeq1--]; (*res2)[indiceRes++] = -1; } // printf("indice Res = %d \n", indiceRes); (*res1)[indiceRes] = '\0'; (*res2)[indiceRes] = '\0'; inverseArray(*res1, strlen(*res1)); inverseArray(*res2, strlen(*res2)); }