예제 #1
0
  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;
  }
예제 #2
0
파일: Table.cpp 프로젝트: BigEd/Cores
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();
//  }
}
예제 #3
0
  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);
	}    
  }
예제 #4
0
  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;
  }
예제 #5
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;
}
예제 #6
0
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;
}
예제 #7
0
 void PrintMemInfo (ostream & ost) const
 {
   ost << "Hash: " << endl;
   hash.PrintMemInfo (ost);
   ost << "Cont: " << endl;
   cont.PrintMemInfo (ost);
 }
예제 #8
0
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");
}
예제 #9
0
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);
}	
예제 #10
0
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);
  }
예제 #12
0
 //outerchartspertrig, sorted!
 int GetOCPTSize() const {return outerchartspertrig.Size();};
예제 #13
0
 void AddEdgePP(int pn, int vn) {edgesperpoint.Add1(pn,vn);};
예제 #14
0
 int GetEdgePP(int pn, int vi)
 {
   if (edgesperpoint.Size() == 0) {BuildEdgesPerPoint();}
   return edgesperpoint.Get(pn,vi);
 };
예제 #15
0
 int GetNEPP(int pn) 
 {
   if (edgesperpoint.Size() == 0) {BuildEdgesPerPoint();}
   return edgesperpoint.EntrySize(pn);
 };
예제 #16
0
 //get NO edges per point
 int GetEPPSize() const {return edgesperpoint.Size();};
예제 #17
0
 int GetBagSize (int bnr) const
 {
   return cont.EntrySize (bnr);
 }
예제 #18
0
 void SetSize(int s) 
 { 
   cont.SetSize(s); 
   BaseSetSize(s);
 }
예제 #19
0
 void BaseSetSize(int s) {hash.SetSize(s);}
예제 #20
0
 const T & Get (const INDEX_2 & ahash) const
 {
   int bnr = HashValue (ahash);
   int pos = Position (bnr, ahash);
   return cont.Get (bnr, pos);
 }
예제 #21
0
 int HashValue (const INDEX & ind) const
   {
     return ind % hash.Size() + 1;
   }
예제 #22
0
 void SetOCPT(int tn, int vi, int ocn) {outerchartspertrig.Set(tn,vi,ocn);};
예제 #23
0
  void SetData (int bnr, int colnr, 
		const INDEX_2 & ahash, const T & acont) 
  {
    hash.Set(bnr, colnr, ahash);
    cont.Set(bnr, colnr, acont);
  }
예제 #24
0
  void GetData (int bnr, int colnr, 
		INDEX_2 & ahash, T & acont) const
  {
    ahash = hash.Get(bnr, colnr);
    acont = cont.Get(bnr, colnr);
  }
예제 #25
0
 int GetNOCPT(int tn) const {return outerchartspertrig.EntrySize(tn);};
예제 #26
0
 //protected:
 ///
 int HashValue (const INDEX_2 & ind) const
   {
     return (ind.I1() + ind.I2()) % hash.Size() + 1;
   }
예제 #27
0
 int GetOCPT(int tn, int vi) const {return outerchartspertrig.Get(tn,vi);};
예제 #28
0
 int GetNBags () const
 {
   return cont.Size();
 }
예제 #29
0
 void AddOCPT(int tn, int ocn) {outerchartspertrig.Add1(tn, ocn);};
예제 #30
0
 void DeleteData ()
 {
   int n = hash.Size();
   hash.SetSize (n);
   cont.SetSize (n);
 }