Beispiel #1
0
static int dbInsert(tableInfo *tbl, insertArgs *args, response *res, error *err) {
	
	char *columnName = args->columnName;
	printf("Inserting into column '%s'...\n", columnName);

	column *col = (column *) malloc(sizeof(column));
	if (col == NULL) {
		ERROR(err, E_NOMEM);
		goto exit;
	}

	if (columnReadFromDisk(tbl, columnName, col, err)) {
		free(col);
		goto exit;
	}

	// columnPrint(col, "read column from disk in dbInsert");

	if (columnInsert(col, args->value, err)) {
		goto cleanupColumn;
	}

	printf("Inserted into column '%s'\n", columnName);
	RESPONSE_SUCCESS(res);

	columnDestroy(col);

	return 0;

cleanupColumn:
	columnDestroy(col);
exit:
	return 1;
}
Beispiel #2
0
// insert a number of columns for a commit at a location
void columnInsert(int key, int index)
{
    int temp;
    if (index == 9)
        columns[9] = key;
    else {
        temp = columns[index];
        columns[index] = key;
        columnInsert(temp, index+1);
    }
}       
Beispiel #3
0
void printGraph(char *commits[], int numcommits)
{ // please pretend this isn't hideous!
    memset(columns, -1, 10*sizeof(int));
    node *commit, *tempone, *temptwo, *childptr;
    char smallHash[6];
    char *p = printBuffer;
    char line[200];
    
    int i, j, parents, children, numbranches;

    // handle root first
    memset(line, '\0', 100*sizeof(char));
    commit = getNode(commits[0]);
    getFirstSix(commit->commitHash, smallHash);
    columnInsert(commit->key, 0);
    asciiCommit(1, 0, line);
    strcat(line, smallHash);
    printf("%s\n", line);
    numbranches = 1;
    childptr = commit->children[0];
    columns[0] = childptr->key;
    for (i = 1; i < commit->numchildren; i++) {
        columnInsert((commit->children[i])->key, i);
        printf("yikes!\n");
    }

    int numpar, numchild, index1, index2;
    // the rest of the commits!
    for (i = 1; i < numcommits; i++) {
        memset(line, '\0', 100*sizeof(char));
        commit = getNode(commits[i]);
        getFirstSix(commit->commitHash, smallHash);
        numpar = commit->numparents;
        numchild = commit->numchildren;

            /* MERGING */

        if (numpar > 1) { 
            for (j = 1; j < numpar; j++) {
                tempone = commit->parents[j-1];
                index1 = findColumn(commit->commitHash, 9);
                temptwo = commit->parents[j];
                index2 = findColumn(commit->commitHash, index1-1);
                if (index1 < index2) {
                    asciiMerge(index1, index2, numbranches - index2, line);
                    columnDelete(index2);
                }
                else {
                    asciiMerge(index2, index1, numbranches - index1 -1, line);
                    columnDelete(index1);
                }
                numbranches--;
            }
        }   
        
            /* COMMIT LINE */

        index1 = findColumn(commit->commitHash, 9);
        asciiCommit(numbranches, index1, line);
        strcat(line, smallHash);
        strcat(line, "\n");

            /* BRANCHING */

        if (numchild == 1) { // don't branch
            childptr = commit->children[0];
            columns[index1] = childptr->key;
        } else if (numchild == 0) {
        } else { // need to branch
            childptr = commit->children[0];
            columns[index1] = childptr->key;
            for (j = 1; j < numchild; j++) {
                childptr = commit->children[j];
                columnInsert(childptr->key, index1+j);
                numbranches++;
            }
            asciiSplit(numchild, index1, line);
        }
        strcpy(p, line);
        p += strlen(line);
    }
    printf("%s\n", printBuffer);
}