static int compare(OBJECT *obj, FINDTYPE ftype, FINDOP op, void *value, char *propname) { switch (ftype) { case FT_ID: return compare_int((int64)obj->id,op,(int64)*(OBJECTNUM*)value); case FT_SIZE: return compare_int((int64)obj->oclass->size,op,(int64)*(int*)value); case FT_CLASS: return compare_string((char*)obj->oclass->name,op,(char*)value); case FT_MODULE: return compare_string((char*)obj->oclass->module->name,op,(char*)value); case FT_GROUPID: return compare_string((char*)obj->groupid,op,(char*)value); case FT_RANK: return compare_int((int64)obj->rank,op,(int64)*(int*)value); case FT_CLOCK: return compare_int((int64)obj->clock,op,(int64)*(TIMESTAMP*)value); //case FT_PROPERTY: return compare_property_alt(obj,propname,op,value); case FT_PROPERTY: return compare_property(obj,propname,op,value); default: output_error("findtype %s not supported", ftype); /* TROUBLESHOOT This error is caused when an object find procedure uses a comparison operator that isn't allowed on a that header item. Make sure the header item and the comparison operator are compatible and try again. If your GLM file isn't the cause of the problem, try reducing the complexity of the GLM file you are using to isolate which module is causing the error and file a report with the GLM file attached. */ return 0; } }
static int compare_int_items(WT_ITEM *itema, WT_ITEM *itemb) { testutil_assert(itema->size == sizeof(int32_t)); testutil_assert(itemb->size == sizeof(int32_t)); return (compare_int(item_to_int(itema), item_to_int(itemb))); }
int compare_string_size(const void* p1, const void* p2) { int x1 = strlen(((PAIR*) p1)->token), x2 = strlen(((PAIR*) p2)->token); return compare_int(x1, x2); }
static char* decode_v0_log() { const char* v1_log = "jHiccup-2.0.1.logV0.hlog"; FILE* f = fopen(v1_log, "r"); mu_assert("Can not open v1 log file", f != NULL); struct hdr_histogram* accum; hdr_init(1, INT64_C(3600000000000), 3, &accum); struct hdr_histogram* h = NULL; struct hdr_log_reader reader; hdr_timespec timestamp; hdr_timespec interval; hdr_log_reader_init(&reader); int rc = hdr_log_read_header(&reader, f); mu_assert("Failed to read header", rc == 0); int histogram_count = 0; int64_t total_count = 0; while ((rc = hdr_log_read(&reader, f, &h, ×tamp, &interval)) != EOF) { mu_assert("Failed to read histogram", rc == 0); histogram_count++; total_count += h->total_count; int64_t dropped = hdr_add(accum, h); mu_assert("Dropped events", compare_int64(dropped, 0)); free(h); h = NULL; } mu_assert("Wrong number of histograms", compare_int(histogram_count, 81)); mu_assert("Wrong total count", compare_int64(total_count, 61256)); mu_assert("99.9 percentile wrong", compare_int64(1510998015, hdr_value_at_percentile(accum, 99.9))); mu_assert("max value wrong", compare_int64(1569718271, hdr_max(accum))); mu_assert("Seconds wrong", compare_int64(1438869961, reader.start_timestamp.tv_sec)); mu_assert("Nanoseconds wrong", compare_int64(225000000, reader.start_timestamp.tv_nsec)); return 0; }
static char* decode_v3_log() { const char* v3_log = "jHiccup-2.0.7S.logV3.hlog"; FILE* f = fopen(v3_log, "r"); mu_assert("Can not open v3 log file", f != NULL); struct hdr_histogram* accum; hdr_init(1, INT64_C(3600000000000), 3, &accum); struct hdr_histogram* h = NULL; struct hdr_log_reader reader; hdr_timespec timestamp; hdr_timespec interval; hdr_log_reader_init(&reader); int rc = hdr_log_read_header(&reader, f); mu_assert("Failed to read header", validate_return_code(rc)); int histogram_count = 0; int64_t total_count = 0; while ((rc = hdr_log_read(&reader, f, &h, ×tamp, &interval)) != EOF) { mu_assert("Failed to read histogram", validate_return_code(rc)); histogram_count++; total_count += h->total_count; int64_t dropped = hdr_add(accum, h); mu_assert("Dropped events", compare_int64(dropped, 0)); free(h); h = NULL; } mu_assert("Wrong number of histograms", compare_int(histogram_count, 62)); mu_assert("Wrong total count", compare_int64(total_count, 48761)); mu_assert("99.9 percentile wrong", compare_int64(1745879039, hdr_value_at_percentile(accum, 99.9))); mu_assert("max value wrong", compare_int64(1796210687, hdr_max(accum))); mu_assert("Seconds wrong", compare_int64(1441812279, reader.start_timestamp.tv_sec)); mu_assert("Nanoseconds wrong", compare_int64(474000000, reader.start_timestamp.tv_nsec)); return 0; }
static int compare_by_state (GtkTreeModel * m, GtkTreeIter * a, GtkTreeIter * b, gpointer u) { int ret = 0; int sa, sb; tr_torrent *ta, *tb; gtk_tree_model_get (m, a, MC_ACTIVITY, &sa, MC_TORRENT, &ta, -1); gtk_tree_model_get (m, b, MC_ACTIVITY, &sb, MC_TORRENT, &tb, -1); if (!ret) ret = compare_int (sa, sb); if (!ret) ret = compare_by_queue (m, a, b, u); return ret; }
static int compare_string(char *a, FINDOP op, char *b) { switch (op) { case SAME: op=EQ; goto CompareInt; case BEFORE: op=LT; goto CompareInt; case AFTER: op=GT; goto CompareInt; case DIFF: op=NE; goto CompareInt; case LIKE: return match(a, b); case EQ: case LT: case GT: case LE: case GE: case NE: if (!(isdigit(a[0])||a[0]=='+'||a[0]=='-')&&!(isdigit(b[0])||b[0]=='+'||b[0]=='-')) output_warning("compare of strings using numeric op usually does not work"); /* TROUBLESHOOT An attempt to compare two numbers using a string comparison operation is not generally going to work as expected. Check that this is truly the desired comparison and correct it if not. If so and the warning error is not desired you may suppress warnings using <code>#set warning=0</code> in the model file. */ return compare_double(atof(a),op,atof(b)); default: output_error("compare op %d not supported on strings", op); /* TROUBLESHOOT This error is caused when an object find procedure uses a comparison operator that isn't allowed on a that type of property. Make sure the property type and the comparison operator are compatible and try again. If your GLM file isn't the cause of the problem, try reducing the complexity of the GLM file you are using to isolate which module is causing the error and file a report with the GLM file attached. */ return 0; } CompareInt: return compare_int((int64)strcmp(a,b),op,0); }
int main(void) { Timer timer1, timer2; timer1.info(); // print information about the system const int NMAX=20000; int array1[NMAX], array2[NMAX]; for (int i = 0; i < NMAX; i++) { //filld two arrays w/ random data array1[i]=randui(0,100000); array2[i]=array1[i]; } // time a selection sort timer1.start(); for (int i=0; i<NMAX; i++) { for (int j=i+1; j<NMAX; j++) { if ( compare_int((void*)&array1[j],(void*)&array1[i]) < 0 ) { int tmp = array1[i]; array1[i]=array1[j]; array1[j]=tmp; } } } timer1.stop(); printf("The elapsed time for selection sort is %f seconds\n", timer1.cpuTime()); // repeat time for qsort timer2.start(); qsort( (void *)array2, NMAX, sizeof(int), compare_int ); timer2.stop(); printf("The elapsed time for qsort is %f seconds\n", timer2.cpuTime()); return 0; }
static char* writes_and_reads_log() { const char* file_name = "histogram.log"; hdr_timespec timestamp; hdr_timespec interval; hdr_gettime(×tamp); interval.tv_sec = 5; interval.tv_nsec = 2000000; struct hdr_log_writer writer; struct hdr_log_reader reader; hdr_log_writer_init(&writer); hdr_log_reader_init(&reader); int rc = 0; FILE* log_file = fopen(file_name, "w+"); rc = hdr_log_write_header(&writer, log_file, "Test log", ×tamp); mu_assert("Failed header write", validate_return_code(rc)); hdr_log_write(&writer, log_file, ×tamp, &interval, cor_histogram); mu_assert("Failed corrected write", validate_return_code(rc)); hdr_log_write(&writer, log_file, ×tamp, &interval, raw_histogram); mu_assert("Failed raw write", validate_return_code(rc)); fprintf(log_file, "\n"); fflush(log_file); fclose(log_file); log_file = fopen(file_name, "r"); struct hdr_histogram* read_cor_histogram = NULL; struct hdr_histogram* read_raw_histogram = NULL; rc = hdr_log_read_header(&reader, log_file); mu_assert("Failed header read", validate_return_code(rc)); mu_assert("Incorrect major version", compare_int(reader.major_version, 1)); mu_assert("Incorrect minor version", compare_int(reader.minor_version, 2)); mu_assert( "Incorrect start timestamp", compare_timespec(&reader.start_timestamp, ×tamp)); hdr_timespec actual_timestamp; hdr_timespec actual_interval; rc = hdr_log_read( &reader, log_file, &read_cor_histogram, &actual_timestamp, &actual_interval); mu_assert("Failed corrected read", validate_return_code(rc)); mu_assert( "Incorrect first timestamp", compare_timespec(&actual_timestamp, ×tamp)); mu_assert( "Incorrect first interval", compare_timespec(&actual_interval, &interval)); rc = hdr_log_read(&reader, log_file, &read_raw_histogram, NULL, NULL); mu_assert("Failed raw read", validate_return_code(rc)); mu_assert( "Histograms do not match", compare_histogram(cor_histogram, read_cor_histogram)); mu_assert( "Histograms do not match", compare_histogram(raw_histogram, read_raw_histogram)); rc = hdr_log_read(&reader, log_file, &read_cor_histogram, NULL, NULL); mu_assert("No EOF at end of file", rc == EOF); fclose(log_file); remove(file_name); return 0; }
static int compare_int64(int64 a, FINDOP op, int64 b){ return compare_int(a, op, b); }
/** * Checks if tuple match to match_string pattern. * * @param tuple_to_match the tuple to match * @param match_string the match string * @return true if matches */ bool tuple_match_match_string(const struct tuple * tuple_to_match, const char * match_string) { //We check if types match. if(!info_string_match_string_equals(tuple_to_match->tuple_content, match_string)) return false; size_t tuple_to_match_position = strlen(&tuple_to_match->tuple_content[0]) + 1; //skip info_string //Filters //current_match_string_token_start points at first filter character //current_match_string_token_end points at last filter character const char * current_match_string_token_start = match_string; for(;;) { //We gets text from current position to null or comma. char current_match_string_token[TUPLE_CONTENT_LENGTH]; //We are looking for ',' or end of string. const char * current_match_string_token_end = strchr(current_match_string_token_start, ','); if(current_match_string_token_end == NULL) //No comma - end of a string current_match_string_token_end = current_match_string_token_start + strlen(current_match_string_token_start); //Length from start to end. const size_t current_match_string_token_length = current_match_string_token_end - current_match_string_token_start; strncpy(current_match_string_token, current_match_string_token_start, current_match_string_token_length); current_match_string_token[current_match_string_token_length] = 0; current_match_string_token_start = current_match_string_token_end + 1; //If we are not checking - increment tuple pointer if(current_match_string_token_length == 1) { switch(current_match_string_token[0]) { case 'i': { tuple_to_match_position += sizeof(int); break; } case 'f': { tuple_to_match_position += sizeof(double); break; } case 's': { tuple_to_match_position += strlen(&tuple_to_match->tuple_content[0] + tuple_to_match_position) + 1; break; } default: { printf("Unknown match_string character: `%c` (%d)", current_match_string_token[0], current_match_string_token[0]); break; } } } else { char operator_[3]; const char * match_string_post_operator = match_string_extract_operator(current_match_string_token, operator_); switch(current_match_string_token[0]) { case 'i': { int tuple_int; memcpy(&tuple_int, &tuple_to_match->tuple_content[0] + tuple_to_match_position, sizeof(int)); int match_string_post_operator_int = atoi(match_string_post_operator); tuple_to_match_position += sizeof(int); if(!compare_int(operator_, tuple_int, match_string_post_operator_int)) return false; break; } case 'f': { double tuple_double; memcpy(&tuple_double, &tuple_to_match->tuple_content[0] + tuple_to_match_position, sizeof(tuple_double)); double match_string_post_operator_double = atof(match_string_post_operator); tuple_to_match_position += sizeof(tuple_double); if(!compare_double(operator_, tuple_double, match_string_post_operator_double)) return false; break; } case 's': { const char * tuple_string = &tuple_to_match->tuple_content[0] + tuple_to_match_position; size_t tuple_string_length = strlen(tuple_string); if(!compare_string(operator_, tuple_string, match_string_post_operator)) return false; tuple_to_match_position += tuple_string_length + 1; break; } default: { printf("Unknown match_string character: `%c` (%d)", current_match_string_token[0], current_match_string_token[0]); break; } } } //Is it the end of string? if(*current_match_string_token_end == 0) return true; } }