void defaults(){ uint16_t counter; add_num(50); for(counter =5;counter < 100;counter+=2){ add_num(counter); } splay_node(25); splay_node(71); splay_node(31); }
int main() { printf("hello\n"); add_num(); sub_num(); printf("done.\n"); return 0; }
/** * add **/ static VALUE t_add(VALUE self, VALUE value) { root_node root; unsigned int num; Data_Get_Struct(self, struct _root_node, root); add_num(root, NUM2UINT(value)); return self; }
/* adds the given number to bitmapper */ VALUE bm_set(VALUE self, VALUE num) { int status; Bitmapper* map; Data_Get_Struct(self, Bitmapper, map); status = add_num(map, bm_to_ll(num)); if(status==0) return (VALUE)Qtrue; else rb_raise(rb_eTypeError, "not valid number"); }
/** * add **/ static VALUE t_add(VALUE self, VALUE value) { root_node root; if (TYPE(value) != T_FIXNUM) return self; if (VALID_MIN_VALUE > value || VALID_MAX_VALUE < value) return self; Data_Get_Struct(self, struct _root_node, root); add_num(root, NUM2ULONG(value)); return self; }
int main(int argc, char *argv[]) { DBG_PRINT("2+3=%d", add_num(2, 3)); set_tty_input_to_raw_mode(); while (1) { DBG_PRINT("%c", getchar()); } return 0; }
/** * initialize **/ static VALUE t_initialize(int argc, VALUE *argv, VALUE self) { VALUE num; root_node root; Data_Get_Struct(self, struct _root_node, root); if (argc == 1) { while((num = rb_ary_shift(argv[0])) != Qnil) { add_num(root, NUM2UINT(num)); } } return self; }
static void add(int i) { int tmp; mylock(&lock); get_num(&tmp); add_num(&tmp, i); put_num(&tmp); myunlock(&lock); }
/** * initialize **/ static VALUE t_initialize(int argc, VALUE *argv, VALUE self) { VALUE num, ary_element; root_node root; unsigned long i, len; Data_Get_Struct(self, struct _root_node, root); if (argc == 1 && TYPE(argv[0]) == T_ARRAY) { len = RARRAY_LEN(argv[0]); for(i = 0; i < len; i++) { ary_element = rb_ary_entry(argv[0], i); if ((TYPE(ary_element) == T_FIXNUM) && VALID_MIN_VALUE <= ary_element && VALID_MAX_VALUE >= ary_element) { add_num(root, NUM2ULONG(ary_element)); } } } return self; }
int main(int argc, char **argv){ unsigned num_mf = argc-1; // Allocate/open all files for(unsigned i=1; i<argc; i++){ char word[1024]; meanfiles[i-1] = alloc_meanfile(argv[i]); meanfile *mf = meanfiles[i-1]; while(read_word(mf->fd, word) == 1){ if(is_numeric(word)){ add_num(mf, get_numeric(word)); } } } // Ensure that all of the files have the same number of numbers unsigned g_numcount = meanfiles[0]->numcount; for(unsigned i=1; i<num_mf; i++){ meanfile *mf = meanfiles[i]; if(mf->numcount != g_numcount){ fprintf(stderr, "These files have different structures!\n"); exit(2); } } double *meannums = malloc(sizeof(double) * g_numcount); double *minnums = malloc(sizeof(double) * g_numcount); double *maxnums = malloc(sizeof(double) * g_numcount); for(unsigned i=0; i<g_numcount; i++){ // We'll take the arithmetic mean. double sum = 0; double g_min = meanfiles[0]->nums[i]; double g_max = meanfiles[0]->nums[i]; for(unsigned j=0; j<num_mf; j++){ sum += meanfiles[j]->nums[i]; g_min = min(g_min, meanfiles[j]->nums[i]); g_max = max(g_max, meanfiles[j]->nums[i]); } double mean = sum / num_mf; meannums[i] = mean; minnums[i] = g_min; maxnums[i] = g_max; } // Using the first file as a model, spit back out the averaged file. rewind(meanfiles[0]->fd); char word[1024]; char line[1024*1024]; unsigned current_num = 0; while(fgets(line, sizeof(line), meanfiles[0]->fd)){ int first = 1; char* token; const char seps[6] = " \n\r\t"; token = strtok(line, seps); while(token != NULL){ char tmp[strlen(token)]; strcpy(tmp, token); int had_comma = tmp[strlen(tmp)-1] == ','; if(had_comma) tmp[strlen(tmp)-1] = '\0'; int is_num = is_numeric(tmp); if(!first) printf(" "); if(is_num){ char *mr_str = getenv("MEAN_REDUCTION"); if(mr_str && strcmp(mr_str, "min")==0){ printf("%0.3f", minnums[current_num++]); }else if(mr_str && strcmp(mr_str, "max")==0){ printf("%0.3f", maxnums[current_num++]); }else{ printf("%0.3f", meannums[current_num++]); } }else{ printf("%s", tmp); } if(had_comma) printf(","); token = strtok(NULL, seps); first = 0; } printf("\n"); } return 0; }
void add_node(){ uint16_t new_node_key; new_node_key = prompt_long("new node's key:"); add_num(new_node_key); }