int Position (int bnr, const INDEX_2 & ind) const { for (int i = 1; i <= hash.EntrySize (bnr); i++) if (hash.Get(bnr, i) == ind) return i; return 0; }
void TABLE::insert(SYM *sp) { int nn; TypeArray *ta = sp->GetProtoTypes(); TABLE *tab = this; SYM *p; int s1,s2,s3; std::string nm; // std::string sig; if (sp == nullptr || this == nullptr ) { dfs.printf("Null pointer at insert\n"); throw new C64PException(ERR_NULLPOINTER,1); } if (this==&tagtable) { dfs.printf("Insert into tagtable:%s|\n",(char *)sp->name->c_str()); } else dfs.printf("Insert %s into %p", (char *)sp->name->c_str(), (char *)this); dfs.printf("(%s)\n",owner ? (char *)SYM::GetPtr(owner)->name->c_str(): (char *)""); // sig = sp->BuildSignature(); if (tab==&gsyms[0]) { dfs.printf("Insert into global table\n"); s1 = hashadd((char *)sp->name->c_str()); s2 = hashadd((char *)sp->name2->c_str()); s3 = hashadd((char *)sp->name3->c_str()); // tab = &gsyms[(s1&s2)|(s1&s3)|(s2&s3)]; tab = &gsyms[s1]; } nm = *sp->name; // The symbol may not have a type if it's just a label. Find doens't // look at the return type parameter anyway, so we just set it to bt_long // if tp isn't set. nn = tab->Find(nm,sp->tp ? sp->tp->typeno : bt_long,ta,true); if(nn == 0) { if( tab->head == 0) { tab->SetHead(sp->GetIndex()); tab->SetTail(sp->GetIndex()); } else { sp->GetPtr(tab->tail)->next = sp->GetIndex(); tab->SetTail(sp->GetIndex()); } sp->SetNext(0); dfs.printf("At insert:\n"); sp->GetProtoTypes()->Print(); } else error(ERR_DUPSYM); if (ta) delete ta; // p = tab->GetHead(); // while(p) { // printf("Xele:%p|%s|\r\n", p, p->name.c_str()); // p = p->GetNext(); // } }
void Set (const INDEX_2 & ahash, const T & acont) { int bnr = HashValue (ahash); int pos = Position (bnr, ahash); if (pos) cont.Set (bnr, pos, acont); else { hash.Add1 (bnr, ahash); cont.Add1 (bnr, acont); } }
int Position (int bnr, const INDEX_3 & ind) const { const INDEX_3 * pi = &hash.Get(bnr, 1); int n = hash.EntrySize(bnr); for (int i = 1; i <= n; ++i, ++pi) { if (*pi == ind) return i; } return 0; }
void create(ClientMap& clientMap, char ID[], char plainPwd[], TABLE& id_table) { //clientMap.showMap(); if(clientMap.search(ID) != nullptr) { printf("ID %s exists, ", ID); // show 10 unused ID int count = 0; NextWordGenerator gen(ID); while(count != 10) { char *next = gen.getNext(); if(clientMap.search(next) == nullptr) // if the ID doesn't exist, show it { printf("%s%c", next, (count == 9) ? '\n' : ','); count++; } } return; } int pos = id_table.insert(ID); char encryptedPwd[110]; md5(encryptedPwd, plainPwd); clientMap.insert(ID, encryptedPwd, pos); printf("success\n"); return; }
void merge(ClientMap& clientMap, char ID[], char password[], char ID_2[], char password_2[], TABLE &id_table) { ClientData *clientData_1 = clientMap.search(ID); ClientData *clientData_2 = clientMap.search(ID_2); if (clientData_1 == nullptr){ printf("ID %s not found\n", ID); return; } if (clientData_2 == nullptr){ printf("ID %s not found\n", ID_2); return; } char encryptedPwd_1[110]; md5(encryptedPwd_1, password); if (strcmp(clientData_1->md5_password, encryptedPwd_1) != 0){ printf("wrong password1\n"); return; } char encryptedPwd_2[110]; md5(encryptedPwd_2, password_2); if (strcmp(clientData_2->md5_password, encryptedPwd_2) != 0){ printf("wrong password2\n"); return; } clientData_1->money += clientData_2->money; mergeHistory(clientData_1->history, clientData_2->history); char* tempID = id_table.eraser(clientData_2->IDpos, strlen(ID_2)); if (tempID != NULL){ ClientData *backID_clientData = clientMap.search(tempID); backID_clientData->IDpos = clientData_2->IDpos; } clientMap.erase(ID_2); printf("success, %s has %lld dollars\n", ID, clientData_1->money); return; }
void PrintMemInfo (ostream & ost) const { ost << "Hash: " << endl; hash.PrintMemInfo (ost); ost << "Cont: " << endl; cont.PrintMemInfo (ost); }
void remove(ClientMap& clientMap, char ID[], char plainPwd[], TABLE &id_table) { ClientData *clientData = clientMap.search(ID); if (clientData == nullptr){ printf("ID %s not found\n", ID); return; } char encryptedPwd[110]; md5(encryptedPwd, plainPwd); if (strcmp(clientData->md5_password, encryptedPwd) == 0){ char* tempID = id_table.eraser(clientData->IDpos, strlen(ID)); if (tempID != NULL){ ClientData *clientData_2 = clientMap.search(tempID); clientData_2->IDpos = clientData->IDpos; } clientMap.erase(ID); printf("success\n"); } else printf("wrong password\n"); }
void transfer(ClientMap& clientMap, char ID[], char transferID[], LLI money, TABLE& id_table) { ClientData *clientData = clientMap.search(ID); ClientData *transferData = clientMap.search(transferID); if (transferData == nullptr){ id_table.recommendID(transferID); return; } if (clientData->money < money){ printf("fail, %lld dollars only in current account\n", clientData->money); return; } clientData->money -= money; transferData->money += money; transferHistory(clientData->history, ID, transferData->history, transferID, timeStamp, money); timeStamp++; printf("success, %lld dollars left in current account\n", clientData->money); }
void ParseEnumDeclaration(TABLE *table) { SYM *sp; TYP *tp; if( lastst == id) { if((sp = search(lastid,&tagtable)) == NULL) { sp = allocSYM(); sp->tp = TYP::Make(bt_enum,1); sp->storage_class = sc_type; sp->SetName(*(new std::string(lastid))); sp->tp->sname = new std::string(*sp->name); NextToken(); if( lastst != begin) error(ERR_INCOMPLETE); else { tagtable.insert(sp); NextToken(); ParseEnumerationList(table); } } else NextToken(); head = sp->tp; } else { tp = allocTYP(); // fix here tp->type = bt_enum; tp->size = 1; if( lastst != begin) error(ERR_INCOMPLETE); else { NextToken(); ParseEnumerationList(table); } head = tp; } }
inline void MyMPI_ExchangeTable (TABLE<T> & send_data, TABLE<T> & recv_data, int tag, MPI_Comm comm = MPI_COMM_WORLD) { int ntasks, rank; MPI_Comm_size(comm, &ntasks); MPI_Comm_rank(comm, &rank); Array<int> send_sizes(ntasks); Array<int> recv_sizes(ntasks); for (int i = 0; i < ntasks; i++) send_sizes[i] = send_data[i].Size(); MPI_Alltoall (&send_sizes[0], 1, MPI_INT, &recv_sizes[0], 1, MPI_INT, comm); // in-place is buggy ! // MPI_Alltoall (MPI_IN_PLACE, 1, MPI_INT, // &recv_sizes[0], 1, MPI_INT, comm); for (int i = 0; i < ntasks; i++) recv_data.SetEntrySize (i, recv_sizes[i], sizeof(T)); Array<MPI_Request> requests; for (int dest = 0; dest < ntasks; dest++) if (dest != rank && send_data[dest].Size()) requests.Append (MyMPI_ISend (send_data[dest], dest, tag, comm)); for (int dest = 0; dest < ntasks; dest++) if (dest != rank && recv_data[dest].Size()) requests.Append (MyMPI_IRecv (recv_data[dest], dest, tag, comm)); // MPI_Barrier (comm); MPI_Waitall (requests.Size(), &requests[0], MPI_STATUS_IGNORE); }
//outerchartspertrig, sorted! int GetOCPTSize() const {return outerchartspertrig.Size();};
void AddEdgePP(int pn, int vn) {edgesperpoint.Add1(pn,vn);};
int GetEdgePP(int pn, int vi) { if (edgesperpoint.Size() == 0) {BuildEdgesPerPoint();} return edgesperpoint.Get(pn,vi); };
int GetNEPP(int pn) { if (edgesperpoint.Size() == 0) {BuildEdgesPerPoint();} return edgesperpoint.EntrySize(pn); };
//get NO edges per point int GetEPPSize() const {return edgesperpoint.Size();};
int GetBagSize (int bnr) const { return cont.EntrySize (bnr); }
void SetSize(int s) { cont.SetSize(s); BaseSetSize(s); }
void BaseSetSize(int s) {hash.SetSize(s);}
const T & Get (const INDEX_2 & ahash) const { int bnr = HashValue (ahash); int pos = Position (bnr, ahash); return cont.Get (bnr, pos); }
int HashValue (const INDEX & ind) const { return ind % hash.Size() + 1; }
void SetOCPT(int tn, int vi, int ocn) {outerchartspertrig.Set(tn,vi,ocn);};
void SetData (int bnr, int colnr, const INDEX_2 & ahash, const T & acont) { hash.Set(bnr, colnr, ahash); cont.Set(bnr, colnr, acont); }
void GetData (int bnr, int colnr, INDEX_2 & ahash, T & acont) const { ahash = hash.Get(bnr, colnr); acont = cont.Get(bnr, colnr); }
int GetNOCPT(int tn) const {return outerchartspertrig.EntrySize(tn);};
//protected: /// int HashValue (const INDEX_2 & ind) const { return (ind.I1() + ind.I2()) % hash.Size() + 1; }
int GetOCPT(int tn, int vi) const {return outerchartspertrig.Get(tn,vi);};
int GetNBags () const { return cont.Size(); }
void AddOCPT(int tn, int ocn) {outerchartspertrig.Add1(tn, ocn);};
void DeleteData () { int n = hash.Size(); hash.SetSize (n); cont.SetSize (n); }