/* The input file is a file that contains file full path for each line,like /home/user/src/abc.c /home/user/src/adf.c /home/user/src/afe.c /home/user/src/doom.c /home/user/src/elf.c /home/user/src/eep.c /home/user/src/woman.c /home/user/src/what.c The matrix is a 2-D pointer array that contains file infor(name,path) according to a-z order,like 'a' abc.c--->adf.c--->afe.c--->NULL | 'b' NULL | 'c' NULL | 'd' doom.c--->NULL | 'e' elf.c--->eep.c--->NULL | 'f' NULL | ... | 'w' woman.c--->what.c--->NULL | ... 'z' NULL */ void matrix_get(char * file, /* in,input file path */ FILE_INFO_NODE ** matrix) /* out,matrix */ { FILE * fd; FILE_INFO_NODE * fin_temp; FILE_INFO_NODE * fin_cursors[26]; unsigned int index; int c; if ((fd = fopen(file,"r")) == 0) { fprintf(stderr,"Read file(%s) failed:%s\n",file,strerror(errno)); exit(0); } /* create header node */ CREATE_NODE(fin_temp); /* go through file line by line and build a matrix to save sort node link */ while (fgets((char *)fin_temp->fpath, MAX_PATH_LEN, fd) != 0) { strncpy(fin_temp->fname,ft_basename(fin_temp->fpath),MAX_NAME_LEN); #if DEBUG_TRACE == 2 fprintf(stdout, "fname is %s",fin_temp->fname); #endif c = (int)fin_temp->fname[0]; index = tolower(c) - 'a'; if (index > 'z') { /* a source file beginning with a ? */ fprintf(stderr, "Unsupport file name:%s\n",fin_temp->fname); continue; } if (matrix[index] == NULL) { #if DEBUG_TRACE == 2 fprintf(stdout, "add header node at matrix[%d]=0x%p\n",index,matrix[index]); #endif matrix[index] = (FILE_INFO_NODE *)fin_temp; fin_cursors[index] = (FILE_INFO_NODE *)fin_temp; } else { #if DEBUG_TRACE == 2 fprintf(stdout, "append node at matrix[%d]=0x%p,cursors[%d]=0x%p\n\n",index,matrix[index],index,fin_cursors[index]); #endif fin_cursors[index]->next = (FILE_INFO_NODE *)fin_temp; fin_cursors[index] = (FILE_INFO_NODE *)fin_temp; } /* create new node... */ CREATE_NODE(fin_temp); } fclose(fd); /* #if DEBUG_TRACE == 1 matrix_dump(matrix); #endif */ }
TRI_aql_node_t* TRI_CreateNodeScopeEndAql (TRI_aql_context_t* const context, void* data) { CREATE_NODE(TRI_AQL_NODE_SCOPE_END) node->_value._value._data = data; return node; }
int main() { srand(time(NULL)); long i,t,m=10; node *n; for(i=0;i<m;++i){ t=rand()%m+1; n=CREATE_NODE(t); H=FIB_HEAP_INSERT(H,n); //printf("%4ld",t); } //printf("\n"); DISPLAY(H); while(H!=NULL){ printf("%ld\n",H->n); FIB_HEAP_EXTRACT_MIN(H); } }
static TRI_aql_node_t* CreateNodeInternalFcall (TRI_aql_context_t* const context, const char* const name, const char* const internalName, const TRI_aql_node_t* const parameters) { CREATE_NODE(TRI_AQL_NODE_FCALL) TRI_AQL_NODE_DATA(node) = 0; { TRI_aql_function_t* function; TRI_associative_pointer_t* functions; TRI_ASSERT(context->_vocbase); functions = context->_vocbase->_functions; TRI_ASSERT(functions); function = TRI_GetByExternalNameFunctionAql(functions, internalName); if (function == NULL) { // function name is unknown TRI_SetErrorContextAql(__FILE__, __LINE__, context, TRI_ERROR_QUERY_FUNCTION_NAME_UNKNOWN, name); return NULL; } // validate function call arguments if (! TRI_ValidateArgsFunctionAql(context, function, parameters)) { return NULL; } // initialise ADD_MEMBER(parameters) TRI_AQL_NODE_DATA(node) = function; } return node; }
void AdrenoHashtable_Set(AdrenoHashtable *hashtable, void *key, void *value) { hash_t keyHash = GetHash( hashtable, key ); AdrenoHashtableNode *next = hashtable->RootNode; AdrenoHashtableNode *ptr; #define CREATE_NODE(node, parentNode) \ { \ node = (AdrenoHashtableNode *)AdrenoMemoryPool_Alloc(AHT_NodePool); \ if (!node) \ return; \ node->Value.Key = keyHash; \ node->Value.Value = value; \ node->Parent = parentNode; \ node->Left = NULL; \ node->Right = NULL; \ } if (next == NULL) { CREATE_NODE(hashtable->RootNode, NULL); } else { while (next != NULL) { if (keyHash == next->Value.Key) { next->Value.Value = value; break; } else if (keyHash < next->Value.Key) { if (next->Left == NULL) { CREATE_NODE(ptr, next); next->Left = ptr; hashtable->NodeCount++; break; } else { next = next->Left; } } else if (keyHash > next->Value.Key) { if (next->Right == NULL) { CREATE_NODE(ptr, next); next->Right = ptr; hashtable->NodeCount++; break; } else { next = next->Right; } } } } #undef CREATE_NODE }
int bdd_makenode(unsigned int level, int low, int high) { register unsigned int hash; register int res; #ifdef CACHESTATS bddcachestats.uniqueAccess++; #endif /* check whether childs are equal */ if (low == high) return low; /* Try to find an existing node of this kind */ hash = NODEHASH(level, low, high); res = HASH(hash); #if defined(SMALL_NODES) if (res != 0) { int m1 = (level << LEV_LPOS) | low; int m2 = ((level << (LEV_HPOS-LEV_LBITS)) & LEV_HMASK) | high; do { if (bddnodes[res].low_llev == m1 && bddnodes[res].high_hlev == m2) { #ifdef CACHESTATS bddcachestats.uniqueHit++; #endif return res; } res = NEXT(res); #ifdef CACHESTATS bddcachestats.uniqueChain++; #endif } while (res != 0); } #else // SMALL_NODES while(res != 0) { if (LEVEL(res) == level && LOW(res) == low && HIGH(res) == high) { #ifdef CACHESTATS bddcachestats.uniqueHit++; #endif return res; } res = NEXT(res); #ifdef CACHESTATS bddcachestats.uniqueChain++; #endif } #endif // SMALL_NODES /* No existing node -> build one */ #ifdef CACHESTATS bddcachestats.uniqueMiss++; #endif /* Any free nodes to use ? */ if (bddfreepos == 0) { if (bdderrorcond) return 0; /* Try to allocate more nodes */ bdd_gbc(); if ((bddnodesize-bddfreenum) >= usednodes_nextreorder && bdd_reorder_ready()) { longjmp(bddexception,1); } if ((bddfreenum*100) / bddnodesize <= minfreenodes) { bdd_noderesize(1); hash = NODEHASH(level, low, high); } /* Panic if that is not possible */ if (bddfreepos == 0) { bdd_error(BDD_NODENUM); bdderrorcond = abs(BDD_NODENUM); return 0; } } /* Build new node */ res = bddfreepos; bddfreepos = NEXT(bddfreepos); bddfreenum--; bddproduced++; { int next = HASH(hash); CREATE_NODE(res, level, low, high, next); /* Insert node */ SETHASH(hash, res); } return res; }
void Array::EnsureSize(ARRAY_COUNT_TYPE size, VariableDATA *default_value) { #ifdef OPTIMIZE_FAST_ARRAYS if ((size > STATIC_ARRAY_THRESHOLD_MINSIZE) && (!cached_data)) { cached_data = (VariableDATA **)FAST_MALLOC(STATIC_ARRAY_THRESHOLD * sizeof(VariableDATA *)); memset(cached_data, 0, STATIC_ARRAY_THRESHOLD * sizeof(VariableDATA *)); } #endif ARRAY_COUNT_TYPE PREC_TARGET_NODE = -1; NODE *REF_NODE = 0; while (COUNT < size) { ARRAY_COUNT_TYPE DISTRIBUTED_COUNT = COUNT % ARRAY_INCREMENT; ARRAY_COUNT_TYPE TARGET_NODE = COUNT / ARRAY_INCREMENT; if (PREC_TARGET_NODE != TARGET_NODE) { if (TARGET_NODE >= NODE_COUNT) { NODE *NEW_NODE; CREATE_NODE(NEW_NODE); if (LAST) LAST->NEXT = NEW_NODE; else FIRST = NEW_NODE; REF_NODE = NEW_NODE; LAST = NEW_NODE; if (!FIRST) FIRST = NEW_NODE; NODE_COUNT++; } else { NODE *CURRENT_NODE = FIRST; for (ARRAY_COUNT_TYPE i = 0; i < TARGET_NODE; i++) CURRENT_NODE = CURRENT_NODE->NEXT; REF_NODE = CURRENT_NODE; } PREC_TARGET_NODE = TARGET_NODE; } ENSURE_ELEMENTS(REF_NODE, DISTRIBUTED_COUNT); ArrayElement *ELEMENTS = REF_NODE->ELEMENTS; ELEMENTS [DISTRIBUTED_COUNT] = (VariableDATA *)VAR_ALLOC(PIF); ELEMENTS [DISTRIBUTED_COUNT]->TYPE = default_value->TYPE; ELEMENTS [DISTRIBUTED_COUNT]->LINKS = 1; if (default_value->TYPE == VARIABLE_STRING) { ELEMENTS [DISTRIBUTED_COUNT]->CLASS_DATA = 0; CONCEPT_STRING(ELEMENTS [DISTRIBUTED_COUNT]) = CONCEPT_STRING(default_value); } else { if (default_value->CLASS_DATA) { ELEMENTS [DISTRIBUTED_COUNT]->CLASS_DATA = default_value->CLASS_DATA; if (default_value->TYPE == VARIABLE_CLASS) ((CompiledClass *)default_value->CLASS_DATA)->LINKS++; else if (default_value->TYPE == VARIABLE_ARRAY) ((Array *)default_value->CLASS_DATA)->LINKS++; else if (default_value->TYPE == VARIABLE_DELEGATE) { ((CompiledClass *)default_value->CLASS_DATA)->LINKS++; ELEMENTS [DISTRIBUTED_COUNT]->DELEGATE_DATA = default_value->DELEGATE_DATA; } } else if (default_value->TYPE == VARIABLE_NUMBER) ELEMENTS [DISTRIBUTED_COUNT]->NUMBER_DATA = default_value->NUMBER_DATA; } ELEMENTS [DISTRIBUTED_COUNT]->IS_PROPERTY_RESULT = 0; ARRAY_CACHED_RETURN(ELEMENTS [DISTRIBUTED_COUNT], COUNT) COUNT++; } }