Word::Word(string text) { this->text = text; hash = 0; for (int i=0; i<text.size(); i++) { hash = hash * 4 + bases[text[i]]; } DEBUG_IF(true) cout<<"hash: "<<hash<<endl; }
int Word::overlap(vector<int> patternHash) { int tmp = hash; for (int i=0; i<text.size()-1; i++) { tmp = tmp/4; DEBUG_IF(true) cout<<"hash: "<<tmp<<" pattern: "<<patternHash[i]<<endl; if (patternHash[i] == tmp) return 1 + i; } return text.size(); }
void main_ui_create_show_tests () { DEBUG_IF (1, "%d", g_module_supported ()); PtrMainUI main_ui = NULL; main_ui_create (&main_ui); main_ui_show (main_ui); GtkWindow* window = main_ui_get_window (main_ui); g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (main_ui_std_destroy), main_ui); gtk_main(); }
/*! * \brief Convertit une chaine de caractere vers le type ground */ static enum GROUND_TYPE convert_string_to_ground_type (char *string) { enum GROUND_TYPE type = ground_type_unknown; if (strcmp (string, "water") == 0) { type = ground_type_water; } else if (strcmp (string, "ground") == 0) { type = ground_type_ground; } DEBUG_IF ((type != ground_type_unknown) == 0, "%s", string); assert (type != ground_type_unknown); return type; }
/*! * \brief Lit le fichier */ PtrGroundArea ground_area_text_storage_read_file (PtrGroundAreaTextStorage ground_area_text_storage) { assert (ground_area_text_storage != NULL); assert (ground_area_text_storage -> file != NULL); char datatype[32] = ""; char version[32] = ""; int operation_done = 0; FILE *file = ground_area_text_storage -> file; long file_initial_position = ftell (file); jump_over_commentary_sharp (file); operation_done = fscanf ( file, "datatype\t%s\tversion\t%s\n", datatype, version ); // DEBUG_IF (1, "%ld", file_initial_position); // DEBUG_IF (1, "%ld", ftell (file)); // DEBUG_IF (1, "%d", operation_done); // DEBUG_IF (1, "%s", datatype); // DEBUG_IF (1, "%s", version); if (operation_done != 2 || strcmp(ground_area_text_storage -> datatype, datatype) != 0 || strcmp(ground_area_text_storage -> version, version) != 0 ) { fseek (file, file_initial_position, SEEK_SET); return NULL; } /* Recuperation des parametres de configuration */ int width = 0; int length = 0; jump_over_commentary_sharp (file); operation_done = fscanf (file, "width\t%d\n", &width); jump_over_commentary_sharp(file); operation_done += fscanf (file, "length\t%d\n", &length); if (operation_done != 2) { fseek (file, file_initial_position, SEEK_SET); return NULL; } PtrGroundArea ground_area = NULL; ground_area_create (&ground_area, width, length); jump_over_commentary_sharp (file); int trash = 0; operation_done = fscanf (file, "array_width\t%d\n", &trash); operation_done += fscanf (file, "array_length\t%d\n", &trash); int array_width = ground_area -> array_width; int array_length = ground_area -> array_length; int i = 0, j = 0; for (i = 0; i < array_width; i++) { for (j= 0; j < array_length; j++) { int x = 0, y = 0; char type_string[32] = ""; double height = 0.0; enum GROUND_TYPE type = ground_type_unknown; jump_over_commentary_sharp (file); operation_done = fscanf (file, "%d\t%d\t%s\t%lf", &x, &y, type_string, &height); DEBUG_IF (operation_done != 4, "%d", i); DEBUG_IF (operation_done != 4, "%d", j); type = convert_string_to_ground_type (type_string); PtrGround ground = ground_area_get_ground (ground_area, x, y); ground_set_type (ground, type); ground_set_height (ground, height); if (type == ground_type_water) { ground_set_dawning (ground, 1.0); } else { ground_set_dawning (ground, 0.0); } } } return ground_area; }
int main (int argc, char *argv[]) { DEBUG_IF (1, "%d", argc); if (argc == 1) { printf ("Saisissez le nom d'une image pnm\n"); return 1; } char path_image[255]; char path_ground[255]; char type[2]; strcpy (path_image, argv[1]); strcpy (path_ground, argv[2]); DEBUG_IF (1, "%s", path_image); DEBUG_IF (1, "%s", path_ground); FILE *file = NULL, *file_ground = NULL; file = fopen (path_image, "r"); file_ground = fopen (path_ground, "w"); fscanf (file, "%s", type); if (strcmp (type, "P2")) { printf("Type de fichier invalide"); } int array_width = 0, array_length = 0; char poubelle[255]; fgets (poubelle, 255, file); fgets (poubelle, 255, file); fscanf (file, "%d %d", &array_width, &array_length); int i = 0, size = array_width *array_length; fprintf (file_ground, "P2\n"); fprintf (file_ground, "%d %d\n", array_width, array_length); fprintf (file_ground, "%d\n", 255); for (i = 0; i < size; i++) { int grey_intensity = 0; fscanf (file, "%d", &grey_intensity); assert (grey_intensity >= 0 && grey_intensity < 256); int hauteur = (int) ((((PROFONDEUR_MAX + HAUTEUR_MAX) * grey_intensity) / NB_COLOR) - PROFONDEUR_MAX); int color = 0; if (hauteur < 0) { color = 0; } else { color = 255; } fprintf (file_ground, "%d\n", color); } fclose (file); fclose (file_ground); return 0; }