コード例 #1
0
ファイル: polynomial.c プロジェクト: ABZaxxon/CS-School-Work
extern status add_poly( polynomial *p_poly1, polynomial *p_poly2 ) {

  /* Polynomial p_poly1 += p_poly2, p_poly2 = 0 */

  list lastreturn = NULL, match_node ;
  term *p_term, *p_match_term ;
  int coef, degree ;

  while( ( lastreturn = list_iterator( *p_poly1, lastreturn ) ) != NULL ) {
  
    p_term = ( term * ) DATA( lastreturn ) ;
    if( find_key( *p_poly2, (generic_ptr )p_term, cmp_degree, &match_node ) == OK ) {

      p_match_term = ( term * ) DATA( match_node ) ;
      p_term -> coefficient += p_match_term -> coefficient ;
      delete_node( p_poly2, match_node ) ;
      free( p_match_term ) ;
 
    }

  }

  while( empty_list( *p_poly2 ) == FALSE ) {

    if( term_delete( p_poly2, &coef, &degree ) == ERROR ) return ERROR ;

    else if( term_insert( p_poly1, coef, degree ) == ERROR ) return ERROR ;

  }
  
  return OK ;

} 
コード例 #2
0
ファイル: fulltext.c プロジェクト: bhanug/likewise-open
/* Update the %_terms table to map the term [zTerm] to the given rowid. */
static int index_insert_term(fulltext_vtab *v, const char *zTerm, int nTerm,
                             sqlite_int64 iDocid, DocList *p){
  sqlite_int64 iFirst;
  sqlite_int64 iIndexRow;
  DocList doclist;

  int rc = term_chunk_select(v, zTerm, nTerm, iDocid, &iFirst);
  if( rc==SQLITE_DONE ){
    docListInit(&doclist, DL_POSITIONS_OFFSETS, 0, 0);
    if( docListUpdate(&doclist, iDocid, p) ){
      rc = term_insert(v, zTerm, nTerm, iDocid, &doclist);
      docListDestroy(&doclist);
      return rc;
    }
    return SQLITE_OK;
  }
  if( rc!=SQLITE_ROW ) return SQLITE_ERROR;

  /* This word is in the index; add this document ID to its blob. */

  rc = term_select(v, zTerm, nTerm, iFirst, &iIndexRow, &doclist);
  if( rc!=SQLITE_OK ) return rc;

  if( docListUpdate(&doclist, iDocid, p) ){
    /* If the blob is too big, split it in half. */
    if( doclist.nData>CHUNK_MAX ){
      DocList half;
      if( docListSplit(&doclist, &half) ){
        rc = term_insert(v, zTerm, nTerm, firstDocid(&half), &half);
        docListDestroy(&half);
        if( rc!=SQLITE_OK ) goto err;
      }
    }
    rc = term_update(v, iIndexRow, &doclist);
  }

err:
  docListDestroy(&doclist);
  return rc;
}
コード例 #3
0
ファイル: input.c プロジェクト: Nicholas-S/xaric
/*
 * input_add_character: adds the character c to the input buffer, repecting
 * the current overwrite/insert mode status, etc 
 */
void input_add_character(char c, char *unused)
{
    int display_flag = NO_UPDATE;

    cursor_to_input();
    if (THIS_POS < INPUT_BUFFER_SIZE) {
	if (get_int_var(INSERT_MODE_VAR)) {
	    if (THIS_CHAR) {
		char *ptr = NULL;

		ptr = strdup(&(THIS_CHAR));

		THIS_CHAR = c;
		NEXT_CHAR = 0;
		ADD_TO_INPUT(ptr);
		free(ptr);
		if (term_insert(c)) {
		    term_putchar(c);
		    if (NEXT_CHAR)
			display_flag = UPDATE_FROM_CURSOR;
		    else
			display_flag = NO_UPDATE;
		}
	    } else {
		THIS_CHAR = c;
		NEXT_CHAR = 0;
		term_putchar(c);
	    }
	} else {
	    if (THIS_CHAR == 0)
		NEXT_CHAR = 0;
	    THIS_CHAR = c;
	    term_putchar(c);
	}
	THIS_POS++;
	update_input(display_flag);
    }
    if (in_completion == STATE_COMPLETE && c == ' ' && input_lastmsg) {
	new_free(&input_lastmsg);
	*new_nick = 0;
	in_completion = STATE_NORMAL;
    }
}
コード例 #4
0
ファイル: polynomial.c プロジェクト: ABZaxxon/CS-School-Work
extern status read_poly( polynomial *p_poly ) {

  /* Read standard input for coefficients and degrees and create a list of terms( a polynomial). Input is terminated when 0,0 is entered */

  int coef, degree ;

  if( init_list( p_poly ) == ERROR ) return ERROR ;

  do {
    printf( "Enter the coefficient, degree (0,0 when done):" ) ;
    scanf( "%d,%d", &coef, &degree ) ; 
    if( coef != 0 ) {
      if( term_insert( p_poly, coef, degree ) == ERROR ) {
	return ERROR ;
      }
    }
  } while (  coef != 0  || degree != 0  ) ;

  return OK ; 

}