JAsyncQueue *hm_async_queue_new( void ) { JAsyncQueue *queue = hm_new(JAsyncQueue, 1); atomic_set(&queue->ref_count, 1); hm_queue_init(&queue->queue); queue->mutex = hm_mutex_new(); queue->cond = hm_cond_new(); return queue; }
JThreadPool *hm_thread_pool_new(JTPFunc func, void *data, unsigned max_threads, JError **err) { JRealThreadPool *tp; tp = hm_new(JRealThreadPool, 1); tp->thread_pool.func = func; tp->thread_pool.user_data = data; tp->queue = hm_async_queue_new(); tp->max_threads = max_threads ? max_threads : 1; tp->num_threads = 0; hm_thread_pool_start_threads(tp, err); return (JThreadPool*)tp; }
int hm_init(hashMap **hashmap){ hashMap *map = hm_new(MAP_CAPACITY); *hashmap = map; return 1; }
int main(int ac, char **av) { //// // Width, height //// int width = 600; int height = 600; //// // Random generator init //// srand((unsigned) time(0)); //// // Alloc //// vec3_field *vf0 = v3f_random_unit(3, 4, 2), *vf1 = v3f_random_unit(6, 5, 2), *vf2 = v3f_random_unit(8, 11, 2), *vf3 = v3f_random_unit(19, 21, 2); heightmap *hm0 = hm_perlin_noise(width, height, vf0, 0.5), *hm1 = hm_perlin_noise(width, height, vf1, 0.5), *hm2 = hm_perlin_noise(width, height, vf2, 0.5), *hm3 = hm_perlin_noise(width, height, vf3, 0.5); heightmap *hm = hm_new(width, height); //// // Process //// hm_add_scale(hm, hm0, 0.50); hm_add_scale(hm, hm1, 0.25); hm_add_scale(hm, hm2, 0.15); hm_add_scale(hm, hm3, 0.10); //// // SDL TIME! FREE BEERS FOR EVERYONE AND THEIR DOG! // (though, you're the one paying, okay?) //// if(SDL_Init(SDL_INIT_EVERYTHING) < 0) { printf("Error: SDL can't init."); return -1; } SDL_Surface *surface; int running = 1; SDL_Event evt; surface = SDL_SetVideoMode(width, height, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); if(surface == NULL) { printf("Error: Can't set video mode."); return -1; } SDL_WM_SetCaption("Perlin noise test", NULL); while(running) { while(SDL_PollEvent(&evt)) { if(evt.type == SDL_QUIT) { running = 0; } } for(int y = 0; y < height; y++) for(int x = 0; x < width; x++) { Uint8 *pixel = (Uint8 *) surface->pixels + y * surface->pitch + x * 4; *(Uint32 *) pixel = to_pixel(surface->format, hm_get(hm, x, y)); } SDL_Flip(surface); } SDL_Quit(); //// // Dealloc //// v3f_destroy(vf0); v3f_destroy(vf1); v3f_destroy(vf2); v3f_destroy(vf3); hm_destroy(hm0); hm_destroy(hm1); hm_destroy(hm2); hm_destroy(hm3); hm_destroy(hm); }
HashMap *InsertSubsToHashTable(char *fullFileNamePath, int allSubsLinesLength) { int i, endOfLinePos = 0, line_number = 0, firstTextLineIndex = 0; char line_buffer[BUFSIZ]; /* BUFSIZ is defined if you include stdio.h */ FILE *infile; char endOfLine[] = "\n"; HashMap *hm; char *shours, *sminutes, *sseconds, *smiliSeconds, scurTotlaTime[100]; char *ehours, *eminutes, *eseconds, *emiliSeconds, ecurTotlaTime[100]; scurTotlaTime[0] = 0; ecurTotlaTime[0] = 0; char subLines[(BUFSIZ * 2) + 50], **strArr; infile = fopen(fullFileNamePath, "r"); if(!infile) { g_error("Couldn't' open file %s for reading", fullFileNamePath); } //Count number of subtitles in .srt files while(fgets(line_buffer, sizeof(line_buffer), infile)) { ++line_number; } fclose(infile); hm = hm_new(line_number); if (hm == NULL) { g_error("Could'nt allocate hash table"); } int lineIndex = 0; infile = fopen(fullFileNamePath, "r"); if(!infile) { g_error("Couldn't' open file %s for reading", fullFileNamePath); } strArr = (char**)malloc((line_number + 1) * sizeof(char*)); for(i = 0; i < line_number + 1; i++) { strArr[i] = (char*)malloc((BUFSIZ + 1) * sizeof(char)); } while(fgets(line_buffer, sizeof(line_buffer), infile)) { strcpy(strArr[lineIndex], line_buffer); lineIndex++; } fclose(infile); for(i = 0; i < lineIndex; i++) { endOfLinePos = strcspn(strArr[i], endOfLine) + 1; if(endOfLinePos > 8) { if(strcmp(substring(strArr[i], 2, 1), ":") == 0) { shours = substring(strArr[i], 0, 2); sminutes = substring(strArr[i], 3, 2); sseconds = substring(strArr[i], 6, 2); smiliSeconds = substring(strArr[i], 9, 2); firstTextLineIndex = i; strcat(scurTotlaTime, shours); strcat(scurTotlaTime, ":"); strcat(scurTotlaTime, sminutes); strcat(scurTotlaTime, ":"); strcat(scurTotlaTime, sseconds); strcat(scurTotlaTime, ":"); strcat(scurTotlaTime, smiliSeconds); if(strcmp(substring(strArr[i], 13, 3), "-->") == 0) { ehours = substring(strArr[i], 13, 6); eminutes = substring(strArr[i], 20, 2); eseconds = substring(strArr[i], 23, 2); emiliSeconds = substring(strArr[i], 26, 2); strcat(ecurTotlaTime, ehours); strcat(ecurTotlaTime, ":"); strcat(ecurTotlaTime, eminutes); strcat(ecurTotlaTime, ":"); strcat(ecurTotlaTime, eseconds); strcat(ecurTotlaTime, ":"); strcat(ecurTotlaTime, emiliSeconds); hm_put(hm, ecurTotlaTime, ""); //insert end time } strcat(subLines, strArr[firstTextLineIndex + 1]); strcat(subLines, strArr[firstTextLineIndex + 2]); hm_put(hm, scurTotlaTime, subLines); //insert start time strcpy(scurTotlaTime, ""); //clean string strcpy(ecurTotlaTime, ""); //clean string strcpy(subLines, ""); //clean string } } } free(shours); free(sminutes); free(sseconds); free(smiliSeconds); free(ehours); free(eminutes); free(eseconds); free(emiliSeconds); free_matrix(strArr, line_number - 1); return hm; }
JList *hm_list_alloc( void ) { JList *list = hm_new(JList, 1); return list; }