/* add_job(string/table output, string label, string command, ...) */ int lf_add_job(lua_State *L) { struct JOB *job; struct CONTEXT *context; if(lua_gettop(L) < 3) luaL_error(L, "add_job: too few arguments"); /*luaL_checktype(L, 1, LUA_TSTRING); */ luaL_checktype(L, 2, LUA_TSTRING); luaL_checktype(L, 3, LUA_TSTRING); /* fetch contexst from lua */ context = context_get_pointer(L); /* create the job */ job = node_job_create(context->graph, lua_tostring(L,2), lua_tostring(L,3)); /* create the nodes */ deep_walk(L, 1, 1, callback_addjob_node, job); /* seek deps */ deep_walk(L, 4, lua_gettop(L), callback_addjob_deps, job); return 0; }
/* add_dependency(string node, string dependency) */ static int add_node_attribute(lua_State *L, const char *funcname, struct NODE *(*callback)(struct NODE*, const char *)) { struct NODE *node; struct CONTEXT *context; int n = lua_gettop(L); struct NODEATTRIB_CBINFO cbinfo; if(n < 2) luaL_error(L, "%s: to few arguments", funcname); luaL_checktype(L, 1, LUA_TSTRING); context = context_get_pointer(L); node = node_find(context->graph, lua_tostring(L,1)); if(!node) luaL_error(L, "%s: couldn't find node with name '%s'", funcname, lua_tostring(L,1)); /* seek deps */ cbinfo.node = node; cbinfo.callback = callback; deep_walk(L, 2, n, callback_node_attrib, &cbinfo); return 0; }
int main() { tnode_t *n; searchTree_t tree; tree.root = NULL; tree.size = 0; int loops = 10; int i,rd; int max = 9; int status = -2; srand(time(NULL)); for(i = 1;i<= loops;i++) { rd = rand() % max + 1; printf("rd:%d\n",rd); n = malloc(sizeof(tnode_t)); n->data = rd; status = tree_insert(&tree,n); if(status == -1) printf("insert error\n"); // inorder_walk_tree(tree.root,print_tnode); printf("\n"); } inorder_walk_tree(tree.root,print_tnode); printf("\n"); printf("deep walk\n"); deep_walk(tree.root); struct timeval start,end; gettimeofday(&start,NULL); tnode_t *r = tree_search_v1(tree.root , max - 1); gettimeofday(&end,NULL); if(r == NULL) printf("not found\n"); else printf("found %d at 0x%x\n",r->data,(unsigned int)r); printf("it takes %ld seconds,%ld micorseconds in v1\n",(long)(end.tv_sec - start.tv_sec),(long)(end.tv_usec - start.tv_usec)); r = NULL; gettimeofday(&start,NULL); r = tree_search_v2(tree.root , max - 1); gettimeofday(&end,NULL); if(r == NULL) printf("not found\n"); else printf("found %d at 0x%x\n",r->data,(unsigned int)r); printf("it takes %ld seconds,%ld micorseconds in v2\n",(long)(end.tv_sec - start.tv_sec),(long)(end.tv_usec - start.tv_usec)); tnode_t * min = tree_min(tree.root); if(min != NULL) printf("min is %d\n",min->data); tnode_t * mx = tree_max(tree.root); if(mx != NULL) printf("max is %d\n",mx->data); tnode_t *s = tree_successor(min); tnode_t *pre = tree_predecessor(s); printf("successor of min is %d\n",s->data); printf("predecessor of s is %d\n",pre->data); tnode_t *pre2 = tree_predecessor(mx); tnode_t *s2 = tree_successor(pre2); printf("predecessor of max is %d\n",pre2->data); printf("successor of pre2 is %d\n",s2->data); tree_delete(&tree, min); printf("delete\n"); inorder_walk_tree(tree.root,print_tnode); printf("\n"); printf("deep walk\n"); deep_walk(tree.root); tree_destroy(tree.root); }