int test(){ T t ; t.x =1; t.y =2; T t1 = {3,4}; Find f =&find; ListPtr list = initList(NULL,NULL); insertToList(list, &t, sizeof(t)); insertToList(list, &t1, sizeof(t1)); int a =1; void*args[0]; args[0]=&a; T* s = getFromList(list,f,args); //printf("%d %d\n", s->y, t.y); insertToList(list, &t1,sizeof(t1)); insertToList(list, &t1,sizeof(t1)); insertToList(list, &t1,sizeof(t1)); insertToList(list, &t1,sizeof(t1)); insertToList(list, &t1,sizeof(t1)); a = 1; T* r = getFromList(list,f,args); printf("%d\n", r->y); printf("count %d\n", getCount(list)); displayList(list,display,4); printf("remove %d\n",removeFromList(list,f,args)); displayList(list,display,4); r = getFromList(list,f,args); //printf("%d\n", r); assert(r==NULL); displayList(list,display,4); t1.y=10; a = 3; int count = setToList(list,&t1,sizeof(t1),f,args); printf("update %d\n", count); displayList(list,display,4); ListPtr ptr = list; int i = 0; do{ void * data = NULL; if(i>4){ data= preFromList(&ptr,list,f,args); }else{ data = nextFromList(&ptr,list,f,args); } if(ptr != list){ display(data,ptr->id); printf("\n"); } i++; }while(ptr!=list); //displayList(list,display,4); int num = freeList(&list); printf("%d\n", num); }
void ConnectivityGraph::removeNontreeEdge( Edge * e, ETForestLevel l ) { Vertex & u( vertices[e->vxid1] ); Vertex & v( vertices[e->vxid2] ); // remove e from adjacency lists EdgeIP eu = getFromList( e->vxid1, e->vxid2, u.adjNontreeEdges[l], l ); EdgeIP ev = getFromList( e->vxid1, e->vxid2, v.adjNontreeEdges[l], l ); assert( eu != NULL && eu == ev ); u.ETvertices[l].loopNode->addWeight( -1, ETWeight::Nontree ); v.ETvertices[l].loopNode->addWeight( -1, ETWeight::Nontree ); }
ConnectivityGraph::EdgeIP ConnectivityGraph::getFromAdjLists( Vertex & u, Vertex & v, ETForestLevel l, bool isTree ) { VertexID uvid( u.getETVertexID() ); VertexID vvid( v.getETVertexID() ); // look for the specified edge in the set of tree edges, organized by level // (note that this erases the edge from the adjacency lists) EdgeIP e = NULL; EdgeIP eu = NULL, ev = NULL; AdjacencyList * l1 = ( isTree ? &u.adjTreeEdges[l] : &u.adjNontreeEdges[l] ); AdjacencyList * l2 = ( isTree ? &v.adjTreeEdges[l] : &v.adjNontreeEdges[l] ); if ( l2->size() < l1->size() ) std::swap( l1, l2 ); eu = getFromList( uvid, vvid, *l1, l ); ev = getFromList( uvid, vvid, *l2, l ); // if ( eu == NULL || ev == NULL ) e = NULL; if ( eu == NULL && ev == NULL ) { std::cout << "getFromAdjList: " << uvid << ", " << vvid << " for vertices "<< std::endl; std::cout << "list l1: "; printContainer( *l1 ); std::cout << "\n"; std::cout << "list l2: "; printContainer( *l2 ); std::cout << "\n"; } assert( eu != NULL && ev != NULL ); if ( eu != ev ) { std::cout << "nt w: " << v.ETvertices[l].loopNode->weight[ETWeight::Nontree] << ", t w: " << v.ETvertices[l].loopNode->weight[ETWeight::Nontree] << std::endl; std::cout << *ev << ", l = " << l << std::endl; } assert( eu == ev ); assert( eu->level == l ); // assert( eu->count == 0 ); if ( eu != NULL ) { e = eu; // decrease the appropriate weight now that we've removed it ETWeight::Type t = ( e->isTree ? ETWeight::Tree : ETWeight::Nontree ); u.ETvertices[e->level].loopNode->addWeight( -1, t ); v.ETvertices[e->level].loopNode->addWeight( -1, t ); } return e; }
NodeT *getFromList(NodeL **pointer) { NodeT *p; NodeL *firstFromList=*pointer; *pointer=(*pointer)->next; if(strcmp(firstFromList->data,"*")==0) return NULL; else { p=createNODE(firstFromList->data); p->left=getFromList(pointer); p->right=getFromList(pointer); return p; } }
int isInTrie(Trie trie, char *w) { size_t length = strlen(w); int curState = 0; for (int i = 0; i < length; i++) { int next = getFromList(trie->transition[curState], w[i]); if (next < 0) { return 0; } else { curState = next; } } return trie->finite[curState]; }
int main() { input=fopen("input.dat", "r"); output=fopen("output.dat","w"); NodeT *root = createBinTree(); NodeL *firstFromList = getListFromTree(root); traverseList(firstFromList); root=getFromList(&firstFromList); prettyPrint(root, 0); return 0; }
void ConnectivityGraph::raiseTreeEdges( ETNode * n, ETForestLevel l ) { assert( n->isLoop() ); Vertex & u( vertices[n->vx1->vxid] ); auto & list = u.adjTreeEdges[l]; while ( !list.empty() ) { // get and remove the last edge (efficient in a vector) EdgeIP e = list.back(); assert( e->isTree ); assert( e->level == l ); // removeTreeEdge( e.get(), l ); list.pop_back(); Vertex & v( e->vxid1 == n->vx1->vxid ? vertices[e->vxid2] : vertices[e->vxid1] ); assert( EulerTourTree::connected( &u.ETvertices[l], &v.ETvertices[l] ) ); // remove e from v's adjacency lists EdgeIP ev = getFromList( e->vxid1, e->vxid2, v.adjTreeEdges[l], l ); assert( ev == e ); u.ETvertices[l].loopNode->addWeight( -1, ETWeight::Tree ); v.ETvertices[l].loopNode->addWeight( -1, ETWeight::Tree ); // get the previous roots on level l+1 ETNode * ru = u.ETvertices[l+1].loopNode->findRoot(); ETNode * rv = v.ETvertices[l+1].loopNode->findRoot(); assert( ru != rv ); // remove the previous roots removeRoot( ru, l+1 ); removeRoot( rv, l+1 ); // move the edge up a level, add it to this new level (and the forest) e->level = l + 1; ETNode * newroot = addTreeEdge( u, v, e, l+1 ); // remember the new root insertRoot( newroot, l+1 ); } }
int insertInTrie(Trie trie, char *w) { size_t length = strlen(w); int curState = 0; for (int i = 0; i < length; i++) { int next = getFromList(trie->transition[curState], w[i]); if (next > -1) { curState = next; } else { trie->transition[curState] = addToList(trie->transition[curState], trie->nextNode, w[i]); curState = trie->nextNode; trie->nextNode = trie->nextNode + 1; } } trie->finite[curState] = 1; return curState; }
static XGMCommand* XGMCommand_createPSGCommand(List* commands, int* offset) { const int size = min(16, commands->size - *offset); unsigned char* data = malloc(size + 1); int i, off; data[0] = XGM_PSG | (size - 1); off = 1; for (i = 0; i < size; i++) data[off++] = VGMCommand_getPSGValue(getFromList(commands, i + *offset)); // remove elements we have done *offset += size; return XGMCommand_create(data, size + 1); }
XGMCommand* XGMCommand_createYMKeyCommand(List* commands, int* offset, int max) { const int size = min(max, commands->size - *offset); unsigned char* data = malloc(size + 1); int i, off; data[0] = XGM_YM2612_REGKEY | (size - 1); off = 1; for (i = 0; i < size; i++) data[off++] = VGMCommand_getYM2612Value(getFromList(commands, i + *offset)); // remove elements we have done *offset += size; return XGMCommand_create(data, size + 1); }
List* XGMCommand_createPCMCommands(XGM* xgm, VGM* vgm, List* commands) { List* result; int i; // allocate result = createList(); for(i = 0; i < commands->size; i++) { VGMCommand* command = getFromList(commands, i); if (VGMCommand_isStreamStartLong(command) || VGMCommand_isStreamStart(command) || VGMCommand_isStreamStop(command)) addToList(result, XGMCommand_createPCMCommand(xgm, vgm, command, -1)); } return result; }
QueryIdentifier QueryContext::findClass(const String& inAlias) const { // look for alias match QueryIdentifier _class; if (_AliasClassTable.lookup(inAlias, _class)) return _class; // look if inAlias is really a class name CIMName _aliasName(inAlias); Array<QueryIdentifier> _identifiers = getFromList(); for (Uint32 i = 0; i < _identifiers.size(); i++) { if (_aliasName == _identifiers[i].getName()) return _identifiers[i]; } // could not find inAlias return QueryIdentifier(); }
static XGMCommand* XGMCommand_createYMPort1Command(List* commands, int* offset) { const int size = min(16, commands->size - *offset); unsigned char* data = malloc((size * 2) + 1); int i, off; data[0] = XGM_YM2612_PORT1 | (size - 1); off = 1; for (i = 0; i < size; i++) { VGMCommand* command = getFromList(commands, i + *offset); data[off++] = VGMCommand_getYM2612Register(command); data[off++] = VGMCommand_getYM2612Value(command); } // remove elements we have done *offset += size; return XGMCommand_create(data, (size * 2) + 1); }
void *FilterPlugin::processEvent(Event *e) { if (e->type() == EventMessageReceived){ Message *msg = (Message*)(e->param()); if (!msg || (msg->type() == MessageStatus)) return NULL; Contact *contact = getContacts()->contact(msg->contact()); FilterUserData *data = NULL; // check if we accept only from users on the list if (getFromList() && ((contact == NULL) || contact->getTemporary())){ delete msg; delete contact; return msg; } if (!contact) return NULL; // check if the user is a ignored user if (contact->getIgnore()){ delete msg; return msg; } // get filter-data data = (FilterUserData*)(contact->getUserData(user_data_id)); if (data && data->SpamList.ptr && *data->SpamList.ptr){ if (checkSpam(msg->getPlainText(), QString::fromUtf8(data->SpamList.ptr))){ delete msg; return msg; } } return NULL; } if (e->type() == EventCheckState){ CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->id == CmdIgnore){ cmd->flags &= ~BTN_HIDE; Contact *contact = getContacts()->contact((unsigned)(cmd->param)); if (contact && contact->getGroup()) cmd->flags |= BTN_HIDE; return e->param(); } if (cmd->id == CmdIgnoreText){ cmd->flags &= ~COMMAND_CHECKED; if (cmd->menu_id == MenuMsgView){ MsgViewBase *edit = (MsgViewBase*)(cmd->param); if (edit->hasSelectedText()) return e->param(); }else if (cmd->menu_id == MenuTextEdit){ TextEdit *edit = ((MsgEdit*)(cmd->param))->m_edit; if (edit->hasSelectedText()) return e->param(); } return NULL; } if (cmd->menu_id == MenuContactGroup){ if (cmd->id == CmdIgnoreList){ Contact *contact = getContacts()->contact((unsigned)(cmd->param)); if (contact == NULL) return NULL; cmd->flags &= COMMAND_CHECKED; if (contact->getIgnore()) cmd->flags |= COMMAND_CHECKED; return e->param(); } } } if (e->type() == EventCommandExec){ CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->id == CmdIgnore){ Contact *contact = getContacts()->contact((unsigned)(cmd->param)); if (contact){ QString text = i18n("Add %1 to ignore list?") .arg(contact->getName()); Command cmd; cmd->id = CmdIgnore; cmd->param = (void*)(contact->id()); Event e(EventCommandWidget, cmd); QWidget *w = (QWidget*)(e.process()); BalloonMsg::ask((void*)(contact->id()), text, w, SLOT(addToIgnore(void*)), NULL, NULL, this); } return e->param(); }
void* countCandidatesThreaded(void *dummyParam) { //printf("DYNAMIC ALGO\n"); ThreadParam* th = (ThreadParam*)dummyParam; UINT level = th->level; UINT tnumCandidates = th->numCandidates; UINT offset = th->offset; UINT** waits = th->waits; UINT* waits_size = th->waits_size; UINT* waits_max = th->waits_max; FLOAT* timestamps = th->timestamps; UINT* timestampSizeAll = th->timestampSizeAll; UINT timestampMatrixSize = level * max_timestamp_per_level; // Initialize sizes of timestamp arrays clearListsAll(timestampSizeAll, level, tnumCandidates); clearCount(h_episodeSupport+offset, tnumCandidates); initWaits(waits, waits_size, waits_max, offset, tnumCandidates, level); for (UINT eventIdx = 0; eventIdx < eventSize; eventIdx++ ) { UBYTE eventSymbol = h_events[eventIdx]; if (cid_flag == 1 && eventIdx > 0) { if (h_cid[eventIdx]!= h_cid[eventIdx-1]) clearListsAll(timestampSizeAll, level, tnumCandidates); } UINT* eps_list = waits[eventSymbol]; for( UINT eps_idx = 0; eps_idx < waits_size[eventSymbol]; eps_idx++) { UINT eps_index = eps_list[eps_idx]; FLOAT* timestampMatrix = ×tamps[timestampMatrixSize * (eps_index - offset)]; UINT* timestampSize = ×tampSizeAll[level * (eps_index - offset)]; UINT gCandidateIdx = level * eps_index; UINT gIntervalIdx = 2*(level-1)* eps_index; bool breakOuterLoop = false; // Check other symbols in the episode for matches to the current event for (int symbolIdx = level-1; symbolIdx >= 0 && !breakOuterLoop; symbolIdx-- ) { if ( eventSymbol == h_episodeCandidates[gCandidateIdx + symbolIdx] ) { if (symbolIdx == 0) { if ( symbolIdx == level-1 ) h_episodeSupport[eps_index]++; else { if (timestampSize[0] > 0 && h_start_times[eventIdx] - getFromList(timestampMatrix, 0, timestampSize[0]-1) > h_episodeIntervals[gIntervalIdx+1]) timestampSize[0] = 0; if (duration_flag == 1) addToList(timestampMatrix, timestampSize, symbolIdx, h_end_times[eventIdx]); else addToList(timestampMatrix, timestampSize, symbolIdx, h_start_times[eventIdx]); } } else if (timestampSize[symbolIdx-1] > 0) { FLOAT distance = h_start_times[eventIdx] - getFromList(timestampMatrix, symbolIdx-1, timestampSize[symbolIdx-1]-1); FLOAT lowerBound = h_episodeIntervals[gIntervalIdx + (symbolIdx-1)*2+0]; FLOAT upperBound = h_episodeIntervals[gIntervalIdx + (symbolIdx-1)*2+1]; if ( distance > upperBound ) { // Clear list timestampSize[symbolIdx-1] = 0; } else { // Check previous for acceptable interval for (int prevIdx = timestampSize[symbolIdx-1]-1; prevIdx >= 0; prevIdx--) { distance = h_start_times[eventIdx] - getFromList(timestampMatrix, symbolIdx-1, prevIdx); if (distance > lowerBound && distance <= upperBound) { if (symbolIdx == level-1) { // The final symbol has been found, clear all lists //#pragma message (__LOC__"### Some thing wrong in usage of offset ###") //episodeSupport[eps_index - offset]++; h_episodeSupport[eps_index]++; clearLists(timestampSize, level); breakOuterLoop = true; } else { if ( timestampSize[symbolIdx] > 0 && h_start_times[eventIdx] - getFromList(timestampMatrix, symbolIdx, timestampSize[symbolIdx]-1) > h_episodeIntervals[gIntervalIdx + 2*(symbolIdx)+1] ) timestampSize[symbolIdx] = 0; if (duration_flag == 1) addToList(timestampMatrix, timestampSize, symbolIdx, h_end_times[eventIdx]); else addToList(timestampMatrix, timestampSize, symbolIdx, h_start_times[eventIdx]); } break; } } } } } } } } return NULL; }
ConnectivityGraph::EdgeIP ConnectivityGraph::getFromAdjLists( Vertex & u, Vertex & v ) { VertexID uvid( u.getETVertexID() ); VertexID vvid( v.getETVertexID() ); EdgeIP e, eu, ev; bool istree = false; ETForestLevel l = 0; // std::cout << "trying to getFromAdjLists edge " << uvid << " -- " << vvid << std::endl; AdjacencyList * l1 = NULL, * l2 = NULL; // look in all of the lists for this edge for ( l = numlevels-1; l >= 0 && !eu && !ev; --l ) { for ( int isT = 0; isT <= 1; ++isT ) { istree = (bool) isT; l1 = ( istree ? &u.adjTreeEdges[l] : &u.adjNontreeEdges[l] ); l2 = ( istree ? &v.adjTreeEdges[l] : &v.adjNontreeEdges[l] ); // find (and remove) the edge from the smaller list if ( !l1->empty() && !l2->empty() ) { if ( l1->size() <= l2->size() ) { eu = getFromList( uvid, vvid, *l1, l ); if ( eu != NULL ) { ev = getFromList( uvid, vvid, *l2, l ); break; } } else { ev = getFromList( uvid, vvid, *l2, l ); if ( ev != NULL ) { eu = getFromList( uvid, vvid, *l1, l ); break; } } } } } if ( eu == NULL || ev == NULL ) { std::cout << "eu NULL? " << (eu == NULL) << ", ev NULL? " << (ev==NULL) << std::endl; if ( eu != NULL ) std::cout << "eu " << *eu << std::endl; if ( ev != NULL ) std::cout << "ev " << *ev << std::endl; std::cout << "istree " << istree << ", lvl " << l << std::endl; std::cout << "l1: "; printContainer( *l1 ); std::cout << std::endl; std::cout << "l2: "; printContainer( *l2 ); std::cout << std::endl; } // make sure we found it, otherwise something went wrong... assert( eu != NULL && ev != NULL ); assert( eu == ev ); if ( eu != NULL ) { e = eu; // decrease the appropriate weight now that we've removed it ETWeight::Type t = ( e->isTree ? ETWeight::Tree : ETWeight::Nontree ); u.ETvertices[e->level].loopNode->addWeight( -1, t ); v.ETvertices[e->level].loopNode->addWeight( -1, t ); } return e; }