int visit(int node, double* E, int* E_size, bool* trimed, bool* visited) { int queue_size = 100; int* q = (int*) mxMalloc(queue_size*sizeof(int)); int head = 0, tail = 0; q[head] = node; head += 1; visited[node] = true; trimed[node] = true; while (tail < head) { int temp = q[tail]; for (int i = 0;i < E_size[temp];i++) { int child = d2i(E[temp*max_len+i])-1; //mexPrintf("temp:%d child:%d\n",temp,child); if (visited[child]) {continue;} visited[child] = true; trimed[child] = true; if (head >= queue_size) { q = double_capacity(q,queue_size); queue_size *= 2; } q[head] = child; head += 1; } tail += 1; } mxFree(q); return tail+1; }
stringnode_ref intern_stringtable(stringtable_ref table, cstring string){ if (table->current_size > table->max_size/2){ double_capacity(table); } hashcode_t hashcode = strhash(string); int index = hashcode % table->max_size; while(table->array[index] != NULL){ if (strcmp(table->array[index]->string,string)==0){ return table->array[index]; } ++index; if (index >= table->max_size){ index = 0; } } stringnode_ref node = malloc(sizeof(stringnode)); node->string = strdup(string); node->hashnumber = hashcode; table->array[index] = node; table->current_size++; return table->array[index]; }