eventloop_t *el_loop_create(int size) { eventloop_t *el; int i; if ((el = rr_malloc(sizeof(*el))) == NULL) goto err; el->events = rr_malloc(sizeof(event_t)*size); el->fired = rr_malloc(sizeof(fired_event_t)*size); el->timers = minheap_create(1, sizeof(ev_timer_t), timer_cmp, timer_cpy, timer_swp); if (el->events == NULL || el->fired == NULL || el->timers == NULL) goto err; el->size = size; el->stop = 0; el->maxfd = -1; el->before_polling = NULL; if (el_context_create(el) == -1) goto err; for (i = 0; i < size; i++) el->events[i].mask = RR_EV_NONE; return el; err: if (el) { rr_free(el->events); rr_free(el->fired); minheap_free(el->timers); rr_free(el); } return NULL; }
robj *createHeapqObject(void) { minheap_t *hq = minheap_create(8, sizeof(hq_item_t), hq_cmp, hq_cpy, hq_swp); minheap_set_freecb(hq, rr_obj_free_callback); robj *o = createObject(OBJ_HEAPQ, hq); o->encoding = OBJ_ENCODING_HEAPQ; return o; }
sche_t sche_create(int32_t max_coro,int32_t stack_size,void (*idel)(void*),void *idel_arg) { init_system_time(10); sche_t s = calloc(1,sizeof(*s)); s->stack_size = stack_size; s->max_coro = max_coro; s->active_list_1 = LINK_LIST_CREATE(); s->active_list_2 = LINK_LIST_CREATE(); s->_minheap = minheap_create(max_coro,_less); s->next_check_timeout = GetSystemMs() + 200; s->co = coro_create(s,0,NULL); s->idel = idel; s->idel_arg = idel_arg; double_link_clear(&s->coros); set_current_coro(s->co); return s; }
AStar_t create_AStar(int xsize,int ysize,int *flags){ AStar_t astar = calloc(1,sizeof(*astar)+sizeof(AStarNode)*xsize*ysize); astar->open_list = minheap_create(xsize*ysize,_less); kn_dlist_init(&astar->close_list); kn_dlist_init(&astar->neighbors); astar->xcount = xsize; astar->ycount = ysize; int i = 0; int j = 0; for( ; i < ysize; ++i) { for(j = 0; j < xsize;++j) { AStarNode *tmp = &astar->map[i*xsize+j]; tmp->x = j; tmp->y = i; tmp->block = flags[i*xsize+j]; } } return astar; }
int main() { int32_t i; u_char* ptr=NULL; const char *a="a", *b="b", *c="c", *d="d", *e="e", *f="f", *g="g"; minheap_t* heap = minheap_create(256); if (heap == NULL) { printf("malloc minheap memory error!\n"); } minheap_insert(heap, 34, (u_char *)a); printf("index:%d\n", (int)minheap_insert(heap, 25, (u_char*)b)); minheap_insert(heap, 89, (u_char *)c); minheap_insert(heap, 4, (u_char *)d); minheap_insert(heap, 12, (u_char *)e); minheap_insert(heap, 25, (u_char *)b); minheap_insert(heap, 10, (u_char *)g); for(i=0; i<minheap_count(heap); i++) { printf("index:%d, weight:%d, ptr:%s\n", i, heap->mh_nodes[i].mn_weight, (char *)heap->mh_nodes[i].mn_ptr); } ptr = minheap_pop(heap); printf("minheap pop ptr:%p\n", ptr); printf("minheap pop ptr:%s\n", ptr); for(i=0; i<minheap_count(heap); i++) { printf("index:%d, weight:%d, ptr:%s\n", i, heap->mh_nodes[i].mn_weight, (char *)heap->mh_nodes[i].mn_ptr); } minheap_free(heap); }
struct timer *new_timer() { struct timer *t = calloc(1,sizeof(*t)); t->_minheap = minheap_create(65536,_less); return t; }
static struct fts_iterator_t *create_fts_iterator(unsigned long size) { struct fts_iterator_t *it = rr_malloc(sizeof(*it)); it->docs = minheap_create(size, sizeof(fts_doc_score_t), fts_cmp, fts_cpy, fts_swp); return it; }