Exemplo n.º 1
0
void 
DgSqrD4Grid2DS::setAddInteriorChildren (const DgResAdd<DgIVec2D>& add, 
                                        DgLocVector& vec) const
{
   if (isCongruent() || radix() == 3)
   {
      const DgIVec2D& lowerLeft = add.address() * radix();

      vector<DgAddressBase*>& v = vec.addressVec();
      for (int i = 0; i < radix(); i++)
      {
         for (int j = 0; j < radix(); j++)
         {
            v.push_back(new DgAddress< DgResAdd<DgIVec2D> >(
             DgResAdd<DgIVec2D>(DgIVec2D(lowerLeft.i() + i, lowerLeft.j() + j), 
                               add.res() + 1)));
         }
      }
   }
   else // must be aligned aperture 4
   {
      // only center square is interior

      DgLocation* tmpLoc = makeLocation(add);
      grids()[add.res() + 1]->convert(tmpLoc);
      vec.push_back(*tmpLoc);

      delete tmpLoc;
   }
   
} // void DgSqrD4Grid2DS::setAddInteriorChildren
Exemplo n.º 2
0
void init_sa()
{	int i,j;
	for (i=1;i<=n;++i)
		rank[i]=i;
	radix(rank,sa,st,255,n);
	rank[sa[1]]=1;
	for (i=2;i<=n;++i)
		if (st[sa[i]]!=st[sa[i-1]])
			rank[sa[i]]=rank[sa[i-1]]+1;
		else rank[sa[i]]=rank[sa[i-1]];
	for (i=1;i<=n;i*=2)
	{	for (j=1;j<=n;++j)
		{	a[j]=rank[j];
			if (i+j<=n)
				b[j]=rank[i+j];
			else b[j]=0;
			sa[j]=j;
		}
		radix(sa,rank,b,n,n);
		radix(rank,sa,a,n,n);
		rank[sa[1]]=1;
		for (j=2;j<=n;++j)
			if (a[sa[j]]!=a[sa[j-1]]||b[sa[j]]!=b[sa[j-1]])
				rank[sa[j]]=rank[sa[j-1]]+1;
			else rank[sa[j]]=rank[sa[j-1]];
		if (rank[sa[n]]==n)
			break ;
	}
}
Exemplo n.º 3
0
static void radix_sort (rec *source, ulong N)
{
// allocate heap memory to avoid the need of additional parameter
        rec *temp = (rec *) malloc (N * sizeof (rec));
        assert (temp != NULL);

        radix (3, N, source, temp);
        radix (2, N, temp, source);
        radix (1, N, source, temp);
        radix (0, N, temp, source);

        free (temp);
}
Exemplo n.º 4
0
void 
DgSqrD4Grid2DS::setAddBoundaryChildren (const DgResAdd<DgIVec2D>& add, 
                                        DgLocVector& vec) const
{
   if (isCongruent() || radix() == 3)
   {
      // no boundary children in this topology; leave vec empty
   }
   else // must be aligned aperture 4
   {
      DgLocation* tmpLoc = makeLocation(add);

      // D8 neighbors is what we want

      DgSqrD8Grid2D d8(network(), grids()[add.res() + 1]->backFrame(), 
                       "dummyD8");
      d8.convert(tmpLoc);
      d8.setNeighbors(*tmpLoc, vec);

      grids()[add.res() + 1]->convert(vec);
      convert(vec);

      delete tmpLoc;
   }

} // void DgSqrD4Grid2DS::setAddBoundaryChildren
Exemplo n.º 5
0
        CharT toChar( ValueT val )
        {
            APL_ASSERT( val >= 0 && val < radix() );

            if( val > 9 ) val += 'A' - '9' - 1;
                
            return static_cast<CharT>('0' + val);
        }
Exemplo n.º 6
0
        bool toVal( CharT ch, ValueT &val )
        {
            if( ch >= '0' && ch < '0' + radix() )
            {
                val = ch - '0';
                return true;
            }

            return false;
        }
Exemplo n.º 7
0
void main()
{
          int k,n,r;
    
             FILE * f=fopen("input.txt","r");
             fscanf(f,"%d",&n);
             
             fscanf(f,"%d",&k);
             fscanf(f,"%d",&r);
     
             
          char ** str=(char **) malloc(n*256);
          int i;
          
          for(i=0;i<n;i++)
             str[i]=(char *) malloc(k);
             
             
             
             for(i=0;i<n;i++)
                 fscanf(f,"%s",str[i]);
             
             
             for(i=0;i<n;i++)
                 printf("%s\n",str[i]);
             printf("\n\n");
             FILE * f1=fopen("output.txt","w");
              radix(str,k,r,n); 
              for(i=0;i<n;i++)
                 printf("%s\n",str[i]);
              for(i=0;i<n;i++)
                 fprintf(f1,"%s\n",str[i]);
              
             
//              str[0]="AAAB";
//             str[1]="BBCC";
//            str[2]="BCBA";
//             str[3]="ABCA";
//            str[4]="CCBA";
//            for(i=0;i<5;i++)
//          printf("%s \n",str[i]);
// 
//          
         
//     
//      for(i=0;i<5;i++)
//          printf("%s \n",str[i]);
 
    
     
     fclose(f);
     fclose(f1);
     
system("pause");     
}
Exemplo n.º 8
0
void 
DgSqrD4Grid2DS::setAddParents (const DgResAdd<DgIVec2D>& add, 
                               DgLocVector& vec) const
{
//cout << "   setAddParents: " << add << endl;
   if (isCongruent() || radix() == 3)
   {
      DgLocation* tmpLoc = makeLocation(add);
      grids()[add.res() - 1]->convert(tmpLoc);
      convert(tmpLoc);

      vec.push_back(*tmpLoc);

      delete tmpLoc;
   }
   else // must be aligned aperture 4
   {
      // vertices lie in parents

      DgLocation* tmpLoc = makeLocation(add);
      DgPolygon* verts = makeVertices(*tmpLoc);
      delete tmpLoc;

//cout << "   verts 1: " << *verts << endl;

      grids()[add.res() - 1]->convert(*verts);
//cout << "   verts 2: " << *verts << endl;
      convert(*verts);
//cout << "   verts 3: " << *verts << endl;

      for (int i = 0; i < verts->size(); i++)
      {
         bool found = false;

         for (int j = 0; j < vec.size(); j++) 
         {
//cout << "  " << i << " " << j << " " << (*verts)[i] << " " << vec[j];
            if ((*verts)[i] == vec[j]) 
            {
//cout << " YES" << endl;
               found = true;
               break;
            }
//cout << " NO" << endl;
         }
         
         if (!found) vec.push_back((*verts)[i]);
      }
//cout << "   parents: " << vec << endl;

      delete verts;
   }

} // void DgSqrD4Grid2DS::setAddParents
Exemplo n.º 9
0
void radixSort(int *x, int n)
{
    int max=0,i;
    for (i=0; i<n; i++) if (x[i]>max)
        {
            max=x[i];
            assignments++;
        }
    radix(x,n,max,1);
    printToScreen(x,n);
}
Exemplo n.º 10
0
void main()
{
	int a[M],n,i;
	printf("Entr the number of elements: \n");
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	radix(a,n);
	for(i=0;i<n;i++)
		printf("%d  ",a[i]);
}
Exemplo n.º 11
0
void Fourier (
  COMPLEX *in,
  unsigned n,
  COMPLEX *out
)
{
	unsigned r;

	if ((r = radix (n)) < n)
		split (in, r, n / r, out);
	join (in, n / r, n, out);
}
Exemplo n.º 12
0
void main()
{
	int a[10],i,n;
	clrscr();
	printf("Enter the number of elements");
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	radix(a,n);
	for(i=0;i<n;i++)
		printf("\n%d",a[i]);
	getch();
}
Exemplo n.º 13
0
void suffix_array(int *s, int *SA, int n, int K, int level = 0) {
    int n0 = (n+2)/3, n1 = (n+1)/3, n2 = n/3, n02 = n0+n2; 
    int *s12 = pool[level][0], *SA12 = pool[level][1];
    int *s0 = pool[level][2], *SA0 = pool[level][3];
    s12[n02] = s12[n02+1] = s12[n02+2] = 0; SA12[n02] = SA12[n02+1] = SA12[n02+2] = 0;
    for (int i = 0, j = 0; i < n+(n0-n1); i++) { if (i % 3 != 0) { s12[j++] = i; } }
    radix(s12, SA12, s+2, n02, K);
    radix(SA12, s12, s+1, n02, K);
    radix(s12, SA12, s+0, n02, K);
    int name = 0, c0 = -1, c1 = -1, c2 = -1;
    for (int i = 0; i < n02; i++) {
        if (s[SA12[i]] != c0 || s[SA12[i]+1] != c1 || s[SA12[i]+2] != c2)
        { name++; c0 = s[SA12[i]]; c1 = s[SA12[i]+1]; c2 = s[SA12[i]+2]; }
        if (SA12[i] % 3 == 1) { s12[SA12[i]/3] = name; }
        else { s12[SA12[i]/3 + n0] = name; }
    }
    if (name < n02) {
        suffix_array(s12, SA12, n02, name, level+1);
        for (int i = 0; i < n02; i++) { s12[SA12[i]] = i + 1; }
    } else {
        for (int i = 0; i < n02; i++) { SA12[s12[i]-1] = i; }
    }
    for (int i = 0, j = 0; i < n02; i++) { if (SA12[i] < n0) { s0[j++] = 3*SA12[i]; } }
    radix(s0, SA0, s, n0, K);
    for (int p = 0, t = n0-n1, k = 0; k < n; k++) {
        int i = GetI(); int j = SA0[p];
        if (SA12[t] < n0 ? leq(s[i], s12[SA12[t] + n0], s[j], s12[j/3])
                : leq(s[i], s[i+1], s12[SA12[t]-n0+1], s[j], s[j+1], s12[j/3+n0])) {
            SA[k] = i; t++;
            if (t == n02) { for (k++; p < n0; p++, k++) { SA[k] = SA0[p]; } }
        } else { 
            SA[k] = j; p++; 
            if (p == n0) { for (k++; t < n02; t++, k++) { SA[k] = GetI(); } }
        }
    } 
}
Exemplo n.º 14
0
void radix(int *x, int n, int max, int exp)
{
    int lsd[10]= {0},*a,i;
    for (i=0; i<n; i++) lsd[(x[i]/exp)%10]++; assignments+=n;
    for (i=1; i<10; i++) lsd[i]+=lsd[i-1];  assignments+=9;
    for (i=0; i<n; i++)
    {
        a[lsd[(x[i]/exp)%10]--]=x[i];
        assignments++;
    }
    for (i=0; i<n; i++)
    {
        x[i]=a[i];
        assignments++;
    }
    if (max/exp>0) radix(x,n,max,exp*10);
}
Exemplo n.º 15
0
int main()
{
    double z = 1.0;

    cout << "Some inquiries into the nature of double:" << endl
         << "digits(z) = " << digits(z) << endl
         << "epsilon(z) = " << epsilon(z) << endl
         << "huge(z) = " << huge(z) << endl
         << "tiny(z) = " << tiny(z) << endl
         << "max_exponent(z) = " << max_exponent(z) << endl
         << "min_exponent(z) = " << min_exponent(z) << endl
         << "max_exponent10(z) = " << max_exponent10(z) << endl
         << "min_exponent10(z) = " << min_exponent10(z) << endl
         << "precision(z) = " << precision(z) << endl
         << "radix(z) = " << radix(z) << endl;

    Range r = range(z);
    cout << "range(z) = [ " << r.first() << ", " << r.last() << " ]"
         << endl;

    cout << endl << "More obscure properties:" << endl
         << "is_signed(z) = " << is_signed(z) << endl
         << "is_integer(z) = " << is_integer(z) << endl
         << "is_exact(z) = " << is_exact(z) << endl
         << "round_error(z) = " << round_error(z) << endl
         << "has_infinity(z) = " << has_infinity(z) << endl
         << "has_quiet_NaN(z) = " << has_quiet_NaN(z) << endl
         << "has_signaling_NaN(z) = " << has_signaling_NaN(z) << endl
         << "has_denorm(z) = " << has_denorm(z) << endl
         << "has_denorm_loss(z) = " << has_denorm_loss(z) << endl
         << "infinity(z) = " << infinity(z) << endl
         << "quiet_NaN(z) = " << quiet_NaN(z) << endl
         << "signaling_NaN(z) = " << signaling_NaN(z) << endl
         << "denorm_min(z) = " << denorm_min(z) << endl
         << "is_iec559(z) = " << is_iec559(z) << endl
         << "is_bounded(z) = " << is_bounded(z) << endl
         << "is_modulo(z) = " << is_modulo(z) << endl
         << "traps(z) = " << traps(z) << endl
         << "tinyness_before(z) = " << tinyness_before(z) << endl;

    return 0;
}
Exemplo n.º 16
0
 CharT toChar( ValueT val )
 {
     APL_ASSERT( val >= 0 && val < radix() );
     return static_cast<CharT>('0' + val);
 }
Exemplo n.º 17
0
DgSqrD4Grid2DS::DgSqrD4Grid2DS (DgRFNetwork& networkIn, 
               const DgRF<DgDVec2D, long double>& backFrameIn, int nResIn, 
               unsigned int apertureIn, bool isCongruentIn, bool isAlignedIn,
               const string& nameIn)
        : DgDiscRFS2D (networkIn, backFrameIn, nResIn, apertureIn, 
                       isCongruentIn, isAlignedIn, nameIn) 
{ 
   // determine the radix

   radix_ = static_cast<int>(sqrt(static_cast<float>(aperture())));
   if (static_cast<unsigned int>(radix() * radix()) != aperture())
   {
      report(
      "DgSqrD4Grid2DS::DgSqrD4Grid2DS() aperture must be a perfect square",
       DgBase::Fatal);
   }

   if (isAligned() && radix() != 2 && radix() != 3)
   {
      report("DgSqrD4Grid2DS::DgSqrD4Grid2DS() only aligned apertures 4 and 9 "
             " parent/children operators fully implemented", DgBase::Warning);
   }

   // do the grids
  
   long double fac = 1;

   DgDVec2D trans;
   if (isCongruent())
   {
      trans = DgDVec2D(-0.5, -0.5);
   }
   else if (isAligned())
   {
      trans = DgDVec2D(0.0, 0.0);
   }
   else
   {
      report("DgSqrD4Grid2DS::DgSqrD4Grid2DS() grid system must be either "
             "congruent, aligned, or both", DgBase::Fatal);
   }

   for (int i = 0; i < nRes(); i++)
   {
      string newName = name() + "_" + dgg::util::to_string(i);

      //cout << newName << " " << fac << ' ' << trans << endl;

      DgContCartRF* ccRF = new DgContCartRF(network(), newName + string("bf"));

      new Dg2WayContAffineConverter(backFrame(), *ccRF, (long double) fac, 0.0, 
                                    trans); 

      (*grids_)[i] = new DgSqrD4Grid2D(network(), *ccRF, newName);
      new Dg2WayResAddConverter<DgIVec2D, DgDVec2D, long double>
                                                  (*this, *(grids()[i]), i);

      fac *= radix();
   }

} // DgSqrD4Grid2DS::DgSqrD4Grid2DS