int nc_create_arc (struct al * src_post, struct al * dst_pre, void * src, void * dst) { if (al_test (src_post, dst)) return 0; al_add (src_post, dst); al_add (dst_pre, src); return 1; }
/* * find all the leaders (instruction) in the InstrList given, * leaders returned as an ArrayList(set) of Instruction* */ ArrayList *findLeaders(InstrList *iList){ Instruction *temp_ins; ArrayList *leaders = al_newGeneric(AL_LIST_SET, addressCompare, refPrint, NULL); int i=0; //add first instr into leader list Instruction *instr = getInstruction(iList, i); al_add(leaders, (void *)(instr->addr)); for(i=0;i<iList->numInstrs;i++){ Instruction *instr = getInstruction(iList, i); //ignore non-jump instructions and native invocations if(!isBranch(iList, instr) && !isRetInstruction(iList, instr) && !(isInvokeInstruction(iList, instr) && INSTR_HAS_FLAG(instr, INSTR_IS_SCRIPT_INVOKE)) ) continue; /* add: * instr as target of jump * instr immediately after jump */ if(isBranch(iList, instr)){ if(!instr->jmpOffset){ printInstruction(instr); } assert(instr->jmpOffset); al_add(leaders, (void *)(instr->addr + instr->jmpOffset)); assert(instr->length>0); al_add(leaders, (void *)(instr->addr + instr->length)); } else if(isRetInstruction(iList, instr)){ if(i < iList->numInstrs-1){ temp_ins = getInstruction(iList, i+1); al_add(leaders, (void *)(temp_ins->addr)); } } else{ //non-native invoke and document.write() which generate code if(i < iList->numInstrs-1){ assert(isInvokeInstruction(iList, instr) && INSTR_HAS_FLAG(instr, INSTR_IS_SCRIPT_INVOKE)); temp_ins = getInstruction(iList, i+1); al_add(leaders, (void *)(temp_ins->addr)); } } } return leaders; }
/** \brief Returns an array containing all of the elements in this list in proper sequence * \param pList ArrayList* Pointer to arrayList * \return ArrayList* Return (NULL) if Error [pList is NULL pointer] * - (New array) if Ok */ ArrayList* al_clone(ArrayList* pList) { ArrayList* returnAux; returnAux = al_newArrayList(); int i; if(pList != NULL && returnAux!= NULL) { for(i=0;i<pList->size;i++) { al_add(returnAux,al_get(pList,i)); } } else{ if(pList == NULL) { returnAux = NULL; } } //printf("% p / %p \n", pList, returnAux ); return returnAux; }
int main(int argc, char *argv[]) { Array_List *my_list = al_create_list(integer_compare_protocol, integer_deep_copy_protocol, integer_print_protocol); for (int i = 0; i < 50; i++) { My_Integer *p = malloc(sizeof(My_Integer)); p->x = i; al_add(my_list, p); } al_print_list(my_list); My_Integer *koo = malloc(sizeof(My_Integer)); koo->x = 20; if (al_contains(my_list, koo)) printf("Contains...\n"); al_clear_list(my_list); if (al_contains(my_list, koo)) printf("Contains...\n"); else printf("Doesn't contain...\n"); free(my_list); return 0; }
int cargarDesdeArchivoDirectores(ArrayList* listaDirec) { int auxReturn; FILE* f; int flag=0; int aux; eDirector* auxDirec; f=fopen("directores.dat", "rb"); if(f==NULL) { f= fopen("directores.dat", "wb"); if(f==NULL) { return auxReturn; } flag=1; } if(flag ==0) { auxReturn=0; aux=feof(f); while(aux==0) { auxDirec=malloc(sizeof(eDirector)); fread(auxDirec,sizeof(eDirector),1,f); al_add(listaDirec,auxDirec); aux=feof(f); } } return auxReturn; }
int cargarDesdeArchivoPeliculas(ArrayList* lista) { int flag = 0; int auxReturn=-1; int aux; ePelicula* auxPeli; FILE *f; f=fopen("peliculas.dat", "rb"); if(f==NULL) { f= fopen("peliculas.dat", "wb"); if(f==NULL) { return auxReturn; } flag=1; } if(flag ==0) { auxReturn=0; aux=feof(f); while(aux==0) { auxPeli=malloc(sizeof(ePelicula)); fread(auxPeli,sizeof(ePelicula),1,f); al_add(lista,auxPeli); aux=feof(f); } } fclose(f); return auxReturn; }
/** \brief Returns an array containing all of the elements in this list in proper sequence * \param pList ArrayList* Pointer to arrayList * \return ArrayList* Return (NULL) if Error [pList is NULL pointer] * - (New array) if Ok */ ArrayList* al_clone(ArrayList* pList) { ArrayList* returnAux = NULL; int i; if(pList!=NULL) { returnAux =al_newArrayList(); for(i=0;i<pList->size;i++) al_add(returnAux,al_get(pList,i)); } return returnAux; }
static struct h * _pe_comb_new_hist (struct event *e) { struct h *h; struct ec *r; int i; h = h_alloc (e); if(!h)return h;//ALESSANDRO for (r = pe.comb.r; r->h == 0; r = r->r2) { ASSERT (r->r1); ASSERT (EC_ISREAD (r->r1)); ASSERT (r->r1->h); h_add (h, r->r1->h); } h_add (h, r->h); al_add (&h->ecl, pe.comb.r); for (i = 0; i < pe.comb.size; i++) { ASSERT (pe.comb.tab[i].ispre || EC_ISGEN (pe.comb.tab[i].tab[pe.comb.tab[i].i])); for (r = pe.comb.tab[i].tab[pe.comb.tab[i].i]; r->h == 0; r = r->r2) { ASSERT (r->r1); ASSERT (EC_ISREAD (r->r1)); ASSERT (r->r1->h); h_add (h, r->r1->h); } h_add (h, r->h); al_add (&h->ecl, pe.comb.tab[i].tab[pe.comb.tab[i].i]); } /* compute the marking associated to that history, the marking hash, * lists r(h), s(h), the size of the history and return */ h_marking (h); return h; }
main() { struct al *l; int *u; l = al_create(5); al_add(l, new_int(1)); al_add(l, new_int(2)); al_add(l, new_int(3)); printf("%d\n", al_resize(l, 3)); al_dump(l); al_insertat(l, 0, new_int(4)); al_dump(l); printf("%d\n", al_insertat(l, 6, NULL)); printf("%d\n", al_insertat(l, 3, new_int(5))); al_dump(l); printf("%d\n", al_removeat(l, 5)); printf("%d\n", al_removeat(l, 4)); printf("%d\n", al_insertat(l, 2, u = new_int(6))); al_dump(l); printf("%d\n", al_remove(l, u)); al_dump(l); free(l); return 0; }
/** \brief Set a element in pList at index position * \param pList ArrayList* Pointer to arrayList * \param index int Index of the element * \param pElement void* Pointer to element * \return int Return (-1) if Error [pList or pElement are NULL pointer or invalid index] * - ( 0) if Ok * */ int al_set(ArrayList* pList, int index,void* pElement) { int returnAux = -1; if(pList != NULL && pElement != NULL && index>=0 && index<=pList->size) { if(index == pList->size) { al_add(pList,pElement); } else { *((pList->pElements)+index) = pElement; } returnAux = 0; } return returnAux; }
/** \brief Returns an array containing all of the elements in this list in proper sequence * \param pList ArrayList* Pointer to arrayList * \return ArrayList* Return (NULL) if Error [pList is NULL pointer] * - (New array) if Ok */ ArrayList* al_clone(ArrayList* pList) { ArrayList* returnAux = NULL; ArrayList* pList2=al_newArrayList(); int i; if (pList != NULL) { for (i=0; i<al_len(pList) ; i++) { al_add(pList2,pList->pElements+i); //al_add(pList2,al_get(pList(pList->pElements)+i)); } returnAux=pList2; } return returnAux; }
void nuevoDirector(ArrayList* listaDirec) { eDirector* director=malloc(sizeof(eDirector)); showMessage("ingrese nombre del director"); fflush(stdin); gets(director->nombre); showMessage("ingrese Fecha de nacimiento del director (xx/xx/xxxx)"); fflush(stdin); gets(director->nacimiento); showMessage("ingrese pais del director"); fflush(stdin); gets(director->pais); director->codDirec=listaDirec->size; al_add(listaDirec,director); system("cls"); showMessage("DIRECTOR INGRESADO CON EXITO"); system("pause"); system("cls"); }
/** \brief Elimina un empleado de la lista de empleados actuales y los agrega a un historial de exempleados * * \param pList ArrayList* array de donde se eliminara el empleado * \param historyDel ArrayList* array de exempleados donde se guardara el empleado eliminado * \return int en caso de que ambas arrays no sean distintas de NULL retorna 0, caso contrario -1 * */ int deleteEmployee(ArrayList* pList,ArrayList* historyDel) { int option; char continueDo='s'; int indexAux; eEmployee* mostrar=NULL; int returnAux=-1; system("cls"); if(pList!=NULL && historyDel!=NULL) { if(!getInt(&indexAux,"ingrese el legajo del usuario a eliminar","Error usuario no existente",0,pList->size)) { mostrar=(eEmployee*)pList->pop(pList,indexAux-1); al_add(historyDel,((void*) mostrar)); printf("\nUsuario eliminado\n"); system("pause"); } returnAux=0; } return returnAux; }
/** \brief Returns an array containing all of the elements in this list in proper sequence * \param pList ArrayList* Pointer to arrayList * \return ArrayList* Return (NULL) if Error [pList is NULL pointer] * - (New array) if Ok */ ArrayList* al_clone(ArrayList* pList) { ArrayList* returnAux = NULL; int i; if(pList!=NULL) { returnAux=al_newArrayList(); if( returnAux!=NULL) { for(i=0; i<pList->size;i++) { al_add(returnAux,pList->pElements[i]); } } } return returnAux; }
void alta(ArrayList* lista,ArrayList* listaDirec) { int auxDirec; ePelicula* auxPeli=malloc(sizeof(ePelicula)); showMessage("Ingrese titulo"); fflush(stdin); gets(auxPeli->titulo); showMessage("Ingrese nacionalidad"); fflush(stdin); gets(auxPeli->nacionalidad); showMessage("Ingrese anio de la pelicula"); fflush(stdin); scanf("%d",&auxPeli->anioPelicula); showMessage("Ingrese Puntaje de la pelicula xx/100"); fflush(stdin); scanf("%d",&auxPeli->puntaje); showMessage("Ingrese Codigo de director"); fflush(stdin); scanf("%d",&auxPeli->director); auxDirec=validarDirector(listaDirec,auxPeli->director); while(auxDirec!=1) { showMessage("ERROR,DIRECTOR INEXISTENTE REINGRESE"); fflush(stdin); scanf("%d",&auxPeli->director); printf("%d",auxPeli->director); system("pause"); auxDirec=validarDirector(listaDirec,auxPeli->director); } auxPeli->identificador=lista->size; al_add(lista,auxPeli); system("cls"); showMessage("Pelicula Agregada"); system("pause"); system("cls"); }
int run2(void) { // Genero personas para usar en el ArrayList Employee* p0 = newEmployee(14, "JUAN1" ,"LOPEZ", 133.22,5); Employee* p1 = newEmployee(14, "JUAN2" ,"LOPEZ", 233.22,5); Employee* p2 = newEmployee(14, "JUAN3" ,"LOPEZ", 333.22,5); Employee* p3 = newEmployee(14, "JUAN4" ,"LOPEZ", 433.22,5); printEmployee(p0); printEmployee(p1); printEmployee(p2); printEmployee(p3); //__________________________________________ printf("\r\nCargo ArraList...\r\n"); ArrayList* lista = al_newArrayList(); lista->add(lista,p0); lista->add(lista,p1); lista->add(lista,p2); al_add(lista,p3); // forma no orientada a objetos printArrayListEmployee(lista); printf("\r\nRemuevo index 2\r\n"); lista->remove(lista,2); printArrayListEmployee(lista); printf("\r\nContiene p0 ?\r\n"); if(lista->contains(lista,p0)) printf("SI"); else printf("NO"); printf("\r\nContiene p2 ?\r\n"); if(lista->contains(lista,p2)) printf("SI"); else printf("NO"); printf("\r\nAgrego p2 en la posicion 1\r\n"); lista->set(lista,1,p2); // vuelvo a agregar p2 printArrayListEmployee(lista); printf("\r\nClonamos array\r\n"); ArrayList* lista2 = lista->clone(lista); printf("Lista original:%p\r\n",lista); printArrayListEmployee(lista); printf("Lista Clonada:%p\r\n",lista2); printArrayListEmployee(lista2); lista2->sort(lista2, compareEmployee,1); printf("Lista Clonada Ordenada por Edad (UP):%p\r\n",lista2); printArrayListEmployee(lista2); lista2->sort(lista2, compareEmployee,0); printf("Lista Clonada Ordenada por Edad (DOWN):%p\r\n",lista2); printArrayListEmployee(lista); printf("\r\nlista clonada contiene lista?:"); if(lista->containsAll(lista,lista2)) printf("SI"); else printf("NO"); printf("\r\n\r\nPosicion de p2:"); int index = lista->indexOf(lista,p2); printf("%d\r\n",index); printf("\r\nPosicion de p1:"); index = lista->indexOf(lista,p1); printf("%d\r\n",index); printf("\r\n\r\nHacemos push de p1 en la posicion 1\r\n"); lista->push(lista,1,p1); printArrayListEmployee(lista); printf("\r\nObtenemos sub-lista de 1 a 2\r\n"); ArrayList* subLista = lista->subList(lista,1,2); printArrayListEmployee(subLista); printf("\r\n\r\nHacemos pop de p1 en la posicion 1\r\n"); Employee* p1Aux = lista->pop(lista,1); printf("Elemento pop(): %s\r\n",p1Aux->name); printArrayListEmployee(lista); printf("\r\nClear array\r\n"); lista->clear(lista); printArrayListEmployee(lista); printf("\r\nEsta vacio?\r\n"); if(lista->isEmpty(lista)) printf("SI"); else printf("NO"); // Test expansion/contraccion del size printf("\r\n\r\nTest size\r\n"); int j; for(j=0; j<1100; j++) { Employee* pAux = malloc(sizeof(Employee)); sprintf(pAux->name,"Juan %d",j); pAux->salary=j; lista->add(lista,pAux); } printf("Cantidad de elementos:%d\r\n",lista->len(lista)); //printArrayListPersonas(lista); for(j=0; j<1100; j++) { lista->pop(lista,0); } printf("Cantidad de elementos:%d\r\n",lista->len(lista)); //printArrayListPersonas(lista); //____________________________________ printf("\r\nLibero memoria y termino\r\n"); free(p0); free(p1); free(p2); free(p3); lista->deleteArrayList(lista); lista2->deleteArrayList(lista2); system("PAUSE"); return 0; }
int main() { ArrayList* arrayListC=al_newArrayList(); ArrayList* DeleteHistory=al_newArrayList(); ArrayList* Backup=al_newArrayList(); eEmployee* employeeAux; int id=0; int auxInt; int option; char continueDo='s'; // loadCant(arrayListC); loadFile(arrayListC,"Nomina.dat"); loadFile(DeleteHistory,"Exempl.dat"); // loader(arrayListC); do { getInt(&option,"######CASO DE USO ARRAYLIST###\n\n1-Agregar un empleado\n2-Modificar empleado\n3-Eliminar empleado" "\n4-Tamaño de la nomina\n5-Informes\n6-Salir" "\n10-Salir\noption:","Opcion no valida\n",1,8); switch(option) { case 1: employeeAux=loadEmployee(arrayListC); auxInt=findByName(DeleteHistory,employeeAux->name,employeeAux->lastName); if(auxInt==-1) { id++; if(al_add(arrayListC,(void*)employeeAux)) { id--; } } else { getInt(&option,"\nEl empleado ya pertenecia a la empresa, desea agregarlo nuevamente?? \n1-Si\n2-No","Error opcion no valida",1,2); switch(option) { case 1: employeeAux=(ArrayList*)arrayListC->get(DeleteHistory,auxInt); al_push(arrayListC,(employeeAux->id-1),(void*)employeeAux); al_remove(DeleteHistory,auxInt); break; case 2: id++; if(al_add(arrayListC,(void*)employeeAux)) { id--; } } break; } break; case 2: modifyEmployee(arrayListC); break; case 3: deleteEmployee(arrayListC,DeleteHistory); break; case 4: printf("\n\n@@@@@@@@ HISTORIAL @@@@@@@\n\n"); PrintEmployees(DeleteHistory); break; case 5: informes(arrayListC); break; case 6: continueDo='n'; saveToFileActive(arrayListC,"Nomina.dat"); saveToFileActive(DeleteHistory,"Exempl.dat"); break; case 7: break; case 8: al_push(arrayListC,2,loadEmployee(arrayListC)); break; default: break; } } while(continueDo!='n'); // saveCant(arrayListC); return 0; }
static struct event * _pe_comb_new_event (void) { struct trans *t; struct event *e; struct cond *c; int i; t = pe.comb.t; ASSERT (t); ASSERT (t->pre.deg + t->cont.deg == pe.comb.size + 1); /* allocate and initialize the event */ e = gl_malloc (sizeof (struct event)); ls_insert (&u.unf.events, &e->nod); al_init (&e->pre); al_init (&e->post); al_init (&e->cont); al_init (&e->ac); al_init (&e->hist); e->ft = t; ls_insert (&t->events, &e->tnod); e->m = 0; e->id = u.unf.numev++; /* we will update this if we find one history for this event which is * not a cutoff */ e->iscutoff = 1; /* add pe.comb.r->c to either the preset or context of e */ if (pe.comb.ispre) { al_add (&e->pre, pe.comb.r->c); al_add (&pe.comb.r->c->post, e); } else { al_add (&e->cont, pe.comb.r->c); al_add (&pe.comb.r->c->cont, e); } /* set up preset and context */ for (i = 0; i < pe.comb.size; i++) { c = pe.comb.tab[i].tab[pe.comb.tab[i].i]->c; if (pe.comb.tab[i].ispre) { al_add (&e->pre, c); al_add (&c->post, e); } else { al_add (&e->cont, c); al_add (&c->cont, e); } } ASSERT (e->pre.deg == t->pre.deg); ASSERT (e->cont.deg == t->cont.deg); #ifdef CONFIG_DEBUG DPRINT ("+ Event e%d:%s; pre {", e->id, e->ft->name); for (i = e->pre.deg - 1; i >= 0; i--) { c = (struct cond *) e->pre.adj[i]; DPRINT (" c%d:%s", c->id, c->fp->name); } DPRINT ("}; cont {"); for (i = e->cont.deg - 1; i >= 0; i--) { c = (struct cond *) e->cont.adj[i]; DPRINT (" c%d:%s", c->id, c->fp->name); } DPRINT ("}\n"); #endif /* therefore, at this the moment the event has no postset */ return e; }