Exemple #1
0
bool
DCirfile::Find(uns num)
{
	if (SecFile
	 && SecSect
	 && ((SecFound = SecFile->Find(num)) == true))
		return true;

	if (SubSect
	 && ((SubFound = FindNum(CurrSubSect, num)) == true))
		return true;

  // scan current section for line starting with num
  // if not found in section, return false
	if (CurrSect)
		return FindNum(CurrSect, num);

	return false;
}
Exemple #2
0
int main(int argc, char *argv[])
{
	int i, num, data[MAX_NUM];
	srand((unsigned)time(NULL));
	for(i=0; i<INDEX_BOX; i++)//clear hashing table
	{
		indexTable[i].val = i;
		indexTable[i].next = NULL;
	}
	printf("source data : \n\t");
	for(i=0; i<MAX_NUM; i++)
	{
		data[i] = rand()%99+1;//create data with rand()
		printf("[%2d]", data[i]);//print data
		if(i%8 == 7)
			printf("\n\t");
	}
	printf("\n");
	for(i=0; i<MAX_NUM; i++)
	{
		CreateTable(data[i]);//create hashing table
	}
	while(1)
	{
		printf("please input search data(1-99), input -1 to exit: ");
		scanf("%d", &num);
		if(num == -1)
			break;
		i = FindNum(num);
		if(i == 0)
			printf("### data not found %d ###\n", num);
		else
			printf("find data %d, total find %d times\n", num, i);
	}
	printf("\nHashing table: \n");
	for(i=0; i<INDEX_BOX; i++)
		PrintData(i);
	printf("\n");
	return 0;
}
Exemple #3
0
void DSU::FindNumbers(int begin, int end, path_pk *path, vector<int> &lm_numbers, bool shifts, bool noLP, bool debug, bool no_new)
{
  // first resolve small case:
  if (end-begin<4) {
    bool begins = true;
    for (int i=begin+1; i<end; i++) {

      // get the minimum
      short *tmp_str = allocopy(path[i].structure);
      int tmp_en;
      if (pknots) {
        Structure str(seq, tmp_str, s0, s1);
        tmp_en = move_gradient_pk(seq, &str, s0, s1, shifts, 0);
        copy_arr(tmp_str, str.str);
      } else {
        tmp_en = move_gradient(seq, tmp_str, s0, s1, 0, shifts, noLP);
      }
      // speedup
      if (lm_numbers[begin] != -1 && begins && tmp_en == LM[lm_numbers[begin]].energy && str_eq(LM[lm_numbers[begin]].structure, tmp_str)) {
        lm_numbers[i] = lm_numbers[begin];
      } else {
        begins = false;
        if (lm_numbers[end] != -1 && tmp_en == LM[lm_numbers[end]].energy && str_eq(LM[lm_numbers[end]].structure, tmp_str)) {
          lm_numbers[i] = lm_numbers[end];
        }
      }

      if (lm_numbers[i]==-1) {
        lm_numbers[i] = FindNum(tmp_en, tmp_str);

        // update UBlist
        if (lm_numbers[i]==-1 && !no_new) {
          if (gl_maxen < tmp_en) {
            //fprintf(stderr, "exceeds en.: %s %6.2f\n", pt_to_str(tmp_str).c_str(), tmp_en/100.0);
            lm_numbers[i] = AddLMtoTBD(tmp_str, tmp_en, EE_DSU, debug);

          } else {
            if (debug) fprintf(stderr, "cannot find: %s %6.2f\n", pt_to_str_pk(tmp_str).c_str(), tmp_en/100.0);
            // add to list of minima and count with them later...
            lm_numbers[i] = AddLMtoTBD(tmp_str, tmp_en, NORM_CF, debug);
          }
        }
      } else debug_c++;

      free(tmp_str);
    }
    return ;
  }

  // da middle one
  int pivot = (end+begin)/2;

  short *tmp_str = allocopy(path[pivot].structure);
  //fprintf(stderr, "%s\n", pt_to_str(tmp_str).c_str());
  int tmp_en;
  if (pknots) {
    Structure str(seq, tmp_str, s0, s1);
    tmp_en = move_gradient_pk(seq, &str, s0, s1, shifts, 0);
    copy_arr(tmp_str, str.str);
  } else {
    tmp_en = move_gradient(seq, tmp_str, s0, s1, 0, shifts, noLP);
  }
  //fprintf(stderr, "%s\n", pt_to_str(tmp_str).c_str());

  // speed up:
  if (lm_numbers[begin] != -1 && tmp_en == LM[lm_numbers[begin]].energy && str_eq(LM[lm_numbers[begin]].structure, tmp_str)) {
    lm_numbers[pivot] = lm_numbers[begin];
  } else {
    if (lm_numbers[end] != -1 && tmp_en == LM[lm_numbers[end]].energy && str_eq(LM[lm_numbers[end]].structure, tmp_str)) {
      lm_numbers[pivot] = lm_numbers[end];
    }
  }

  // normal behaviour
  if (lm_numbers[pivot]==-1) {
    lm_numbers[pivot] = FindNum(tmp_en, tmp_str);

    // update UBlist
    if (lm_numbers[pivot]==-1 && !no_new) {
      if (gl_maxen < tmp_en) {
        //fprintf(stderr, "exceeds en.: %s %6.2f\n", pt_to_str(tmp_str).c_str(), tmp_en/100.0);
        lm_numbers[pivot] = AddLMtoTBD(tmp_str, tmp_en, EE_DSU, debug);

      } else {
        if (debug) fprintf(stderr, "cannot find: %s %6.2f\n", pt_to_str_pk(tmp_str).c_str(), tmp_en/100.0);
        // add to list of minima and count with them later...
        lm_numbers[pivot] = AddLMtoTBD(tmp_str, tmp_en, NORM_CF, debug);
      }
    }
  } else debug_c++;

  free(tmp_str);

  // continue recursion:
  if ((lm_numbers[pivot]!=lm_numbers[begin] || lm_numbers[pivot]==-1) && pivot-begin>1) FindNumbers(begin, pivot, path, lm_numbers, shifts, noLP, debug, no_new);
  if ((lm_numbers[pivot]!=lm_numbers[end]   || lm_numbers[pivot]==-1)  && end-pivot>1) FindNumbers(pivot, end, path, lm_numbers, shifts, noLP, debug, no_new);

  // return maximal energy
  return ;
}
Exemple #4
0
//-----------------------------------------------------------------------------
bool mglParser::CheckForName(const std::wstring &s)
{
	return !isalpha(s[0]) || s.find_first_of(L"!@#$%%^&*()-+|,.<>:")!=std::wstring::npos || s==L"rnd" || FindNum(s.c_str());
//	return !isalpha(s[0])||s.find_first_of(L".:()")!=std::wstring::npos;
}
Exemple #5
0
//-----------------------------------------------------------------------------
// convert substrings to arguments
void mglParser::FillArg(mglGraph *gr, int k, std::wstring *arg, mglArg *a)
{
	register long n;
	for(n=1;n<k;n++)
	{
		mglDataA *v;	mglNum *f;
		a[n-1].type = -1;
		if(arg[n][0]=='|')	a[n-1].type = -1;
		else if(arg[n][0]=='\'')	// this is string (simplest case)
		{
			a[n-1].type = 1;
			std::wstring &w=arg[n],f;
			wchar_t buf[32];
			long i,i1,ll=w.length();
			for(i=1;i<ll;i++)
			{
				if(w[i]=='\'')
				{
					if(i==ll-1)	continue;
					i++;	i1 = i;
					if(w[i1]==',')	i1++;
					if(w[i1]==0)	continue;
					for(;i<ll && w[i]!='\'';i++);
					if(i>i1)
					{
						if(w[i1]=='!')
						{
							HADT d = mglFormulaCalcC(w.substr(i1+1,i-i1-(w[i]=='\''?1:0)), this, DataList);
							mreal di = imag(d->a[0]), dr = real(d->a[0]);
							if(di>0)	mglprintf(buf,32,L"%g+%gi",dr,di);
							else if(di<0)	mglprintf(buf,32,L"%g-%gi",dr,-di);	// TODO use \u2212 ???
							else	mglprintf(buf,32,L"%g",dr);
							a[n-1].w += buf;	delete d;
						}
						else
						{
							HMDT d = mglFormulaCalc(w.substr(i1,i-i1-(w[i]=='\''?1:0)), this, DataList);
							mglprintf(buf,32,L"%g",d->a[0]);	a[n-1].w += buf;	delete d;
						}
					}
				}
				else	a[n-1].w += w[i];
			}
		}
		else if(arg[n][0]=='{')
		{	// this is temp data
			mglData *u=new mglData;
			std::wstring s = arg[n].substr(1,arg[n].length()-2);
			a[n-1].w = u->s = L"/*"+s+L"*/";
			a[n-1].type = 0;
			ParseDat(gr, s, *u);	a[n-1].d = u;
			u->temp=true;	DataList.push_back(u);
		}
		else if((v = FindVar(arg[n].c_str()))!=0)	// try to find normal variables (for data creation)
		{	a[n-1].type=0;	a[n-1].d=v;	a[n-1].w=v->s;	}
		else if((f = FindNum(arg[n].c_str()))!=0)	// try to find normal number (for data creation)
		{	a[n-1].type=2;	a[n-1].d=0;	a[n-1].v=f->d;	a[n-1].c=f->c;	a[n-1].w = f->s;	}
		else if(arg[n][0]=='!')	// complex array is asked
		{	// parse all numbers and formulas by unified way
			HADT d = mglFormulaCalcC(arg[n].substr(1), this, DataList);
			if(d->GetNN()==1)
			{
				if(CheckForName(arg[n].substr(1)))
				{	a[n-1].type = 2;	a[n-1].v = d->v(0);	a[n-1].c = d->a[0];	}
				else
				{	a[n-1].type = 0;	a[n-1].d = AddVar(arg[n].c_str());	}
				delete d;
			}
			else
			{
				a[n-1].w = L"/*"+arg[n]+L"*/";
				d->temp=true;	DataList.push_back(d);
				a[n-1].type = 0;	a[n-1].d = d;
			}
		}
		else
		{	// parse all numbers and formulas by unified way
			HMDT d = mglFormulaCalc(arg[n], this, DataList);
			if(d->GetNN()==1)
			{
				if(CheckForName(arg[n]))
				{	a[n-1].type = 2;	a[n-1].c = a[n-1].v = d->v(0);	}
				else
				{	a[n-1].type = 0;	a[n-1].d = AddVar(arg[n].c_str());	}
				delete d;
			}
			else
			{
				a[n-1].w = L"/*"+arg[n]+L"*/";
				d->temp=true;	DataList.push_back(d);
				a[n-1].type = 0;	a[n-1].d = d;
			}
		}
	}
}
Exemple #6
0
//-----------------------------------------------------------------------------
mglNum *mglParser::AddNum(const wchar_t *name)
{
	mglNum *v = FindNum(name);
	if(!v)	{	v=new mglNum;	v->s = name;	NumList.push_back(v);	}
	return v;
}
Exemple #7
0
//-----------------------------------------------------------------------------
mglNum *mglParser::FindNum(const char *str)
{
	mglNum *v=0;
	MGL_TO_WCS(str,v = FindNum(wcs));
	return v;
}