Exemplo n.º 1
0
KWStatus SSShiftSort(void)
{
        int i,j,k;
	
	lineCount = 0;
	int lineListSize = 1;
	if(!(lineList = malloc(sizeof(LineList))))
		return KWMEMORYERROR;

        /* compute the size of lineList */
	int numLines = LSNumLines();
        for (i = 0; i < numLines; i++) {
		int numWords = LSNumWords(i);
		for (j = 0; j < numWords; j++) {
			/* exclude lines that start with a noise word */
			if (!WTIsMember(LSGetWord(i,j))){
				if(lineCount == lineListSize){
					if(!(lineList = realloc(lineList, sizeof(lineList)*lineListSize*2)))
						return KWMEMORYERROR;
					lineListSize *= 2;
				}
				lineList[lineCount].lineNum = i;
				lineList[lineCount].shiftNum = j;
				lineCount++;
			}
		}
        }
        // sort the shifted lines 
        qsort(lineList,lineCount,sizeof(LineList),
                (int (*)(const void *, const void *))lineCompare);

        return KWSUCCESS;
}
Exemplo n.º 2
0
KWStatus SSShiftSort(void)
{
clock_t cstart = clock();
  	clock_t cend = 0;
        int i,j,k;

        /* compute the size of lineList */
        lineCount = 0;
        for (i = 0; i < LSNumLines(); i++) {
		for (j = 0; j < LSNumWords(i); j++) {
			/* exclude lines that start with a noise word */
			if (!WTIsMember(LSGetWord(i,j)))
				lineCount++;
		}
        }

        /* allocate space for lineList */
        lineList = calloc(lineCount, sizeof(LineList));
        if (lineList == NULL) {
		lineCount = 0;
                return KWMEMORYERROR;
	}

        /* fill lineList */
        k = 0;
        for (i = 0; i < LSNumLines(); i++) {
                for (j = 0; j < LSNumWords(i); j++) {
			/* exclude lines that start with a noise word */
			if (!WTIsMember(LSGetWord(i,j))) {
				lineList[k].lineNum = i;
				lineList[k].shiftNum = j;
				k++;
			}
                }
        }

        /* sort the shifted lines */
        qsort(lineList,lineCount,sizeof(LineList),
                (int (*)(const void *, const void *))lineCompare);
cend = clock();
//printf ("%.3f Shift cpu sec\n", ((double)cend - (double)cstart)* 1.0e-6);
        return KWSUCCESS;
}