コード例 #1
0
ファイル: Manager.cpp プロジェクト: ValenW/DateBaseProject
void mySort(int *a, int l, int r, char(*str)[300], char *tempStr) {
	int i = l, j = r, mid = a[(r + l) >> 1];
	while (i <= j) {
		while (a[i] < mid) i++;
		while (a[j] > mid) j--;
		if (i <= j) swap(a, str, tempStr, i++, j--);
	}
	if (i < r) mySort(a, i, r, str, tempStr);
	if (l < j) mySort(a, l, j, str, tempStr);
}
コード例 #2
0
ファイル: main.c プロジェクト: imbaqian/data_struct
void Merge_Sort(int B[],int N)
{
	int i;
	int l;
	int p;
	int flag = 0;
	
	for(l = 2; l<=N; l*=2){
		p = l;
		while(p < N){
			if(B[p-1] > B[p]){
				flag = 1;
				break;
			}
			p = p + 2 * l;

		}
		if(flag)
			break;
	}
	
	l = l * 2;
	for(i = 0; i<N; i = i + l){
		if(i+l >= N)
			l = N-i;
		mySort(B+i,l);
	}


		
}
コード例 #3
0
ファイル: Manager.cpp プロジェクト: ValenW/DateBaseProject
void Manager::query() {
	int temp = 0, t = 0, counter = 0;
	char str[30][300];
	int partKey[30];
	char tempStr[300];

	fscanf(testInStream, "%d", &t);
	queryNum = t;
	start = clock();

	while (t--) {
		fscanf(testInStream, "%d", &temp);
		counter = 0;
		int hashKey = getHash(temp, index->getGlobalDepth());
		int pageId = index->getPageId(hashKey);
		int location = buffer->ifPageExist(pageId);
		if (location == -1) {
			location = buffer->choseByClock();
			buffer->readOutPage(location, pageId);
		}

		Page* p = buffer->getPage(location);
		int size = p->getRecordNumber();

		for (int i = 0; i < size; i++) {
			if (getKey(p->getRecord(i)) == temp) {
				strcpy(str[counter], p->getRecord(i));
				partKey[counter] = getPartKey(str[counter]);
				counter++;
			}
		}

		mySort(partKey, 0, counter - 1, str, tempStr);

		for (int i = 0; i < counter; i++)
			fprintf(testOutStream, "%s\n", str[i]);

		fprintf(testOutStream, "-1\n");
	}

	buffer->closeFile();
	index->closeFile();
	fclose(inStream);
	fclose(testOutStream);
	fclose(testInStream);

	finish = clock();
	printf("\n*** Query Finished ***\nCost %fs totally, that is %fmin.\n", (double)(finish - start) / CLOCKS_PER_SEC, (double)(finish - start) / CLOCKS_PER_SEC / 60.0);
	printf("Query Speed: %f query per second.\n", (double)queryNum / ((double)(finish - start) / CLOCKS_PER_SEC));
	printf("Total Buffer I/O times: %d\n", buffer->iotimes);
	printf("Total Index I/O times: %d\n", index->iotimes);
}
コード例 #4
0
ファイル: SNMinMax.c プロジェクト: Suedo/funCstuff
int main(void){
	int arr[10] = {-1 , 2 , -89 , 56 , 8 , 1 , 45 ,-5 , 6 , 6} , min , max , i , j;
	int sum=0,sh,sl;
	long int prod;
	mySort(arr,10);
	for(i=0 ; i < 10 ; i++){
		sum=sum+arr[i];
		printf("%d ",arr[i]);

	}
	printf("\n\n");
	sl = secondLowest(arr,10);
	sh = secondHighest(arr,10);
	prod = posProd(arr,10);
	printf("min : %d , max : %d, sum: %d , secHigh: %d , secLow: %d \n",arr[0],arr[9],sum,sh,sl);
	printf("product of pos numbers : %ld\n",prod);
	getch();
	clrscr();
	return 0;
	
}
コード例 #5
0
void q4Top10Artigos() {
    HashTE *tmp = NULL;
    Top10Entry top10[10] = {};
    initTop10(&top10);
    int i = 0, len = 0, posmin = 0, min = 0;

    for (i = 0; i < CAP; i++) {
        tmp = ht[i];
        while (tmp) {
            len = lenCoAutores(tmp);
            insereTop10(&top10,len,tmp->nome,posmin, min);
            min = recalcMin(&top10, &posmin,10);
            tmp = tmp->seg;
        }
    }
    mySort(&top10);
    reverseTOP10(&top10);
    printf("-----TOP10-----\n");
    for (i = 0; i < 10; i++) {
        printf("%d > %s %d\n", i+1, top10[i].nome, top10[i].nCoautores-1); // Há uma diferença de um coautor em todas as entradas por isso subtrai uma unidade.
    }
}
コード例 #6
0
ファイル: generic_lib.c プロジェクト: leaderwing/test_repo
void* findMaxSizeOfDuplicateSet(void *buf, size_t size, size_t total, int (*compare)(void const *a, void const *b)) {
	char *temp, *result;
	int counter = 0, i, maxCount = -1;

	if(total == 0 || size < 0 || buf == NULL)
		return NULL; // Cannot find the item element

	if((temp = myMalloc(size, total)) == NULL) {
		return NULL;
	}

	if((result = myMalloc(size, total)) == NULL) {
		return NULL;
	}

	mySort(buf, size, total, compare);

	memcpy(temp, buf, size);

	for(i = 0; i < total; i++) {
		if(compare(buf + i * size, temp) == 0) {
			counter++;
		} else {
			memcpy(temp, buf + i * size, size);
			counter = 1;
		}

		if(counter > maxCount) {
			maxCount = counter;
			memcpy(result, buf + i * size, size);
		}
	}

	free(temp);
	return result;
}
コード例 #7
0
ファイル: generic_lib.c プロジェクト: leaderwing/test_repo
int* findMaxDuplicateSet(void *buf, size_t size, size_t total, int *counter, 
	void const *maxNumber, int (*compare)(void const *a, void const *b)) {

	int* result;
	int i;

	*counter = 0;

	if(total == 0 || size < 0 || buf == NULL)
		return NULL; // Cannot find the item element

	if((result = myMalloc(size, total)) == NULL)
		return NULL;

	mySort(buf, size, total, compare);

	for(i = 0; i < total; i++) {
		if(compare(buf + i * size, maxNumber) == 0) {
			result[(*counter)++] = i;
		}
	}

	return result;
}
コード例 #8
0
LetRecNode::LetRecNode(Compiler &compiler, const iter_t &node, bool isProgram)
    : Node(compiler, Node_ExprLetRec), _isProgram(isProgram)
{
    unsigned j;
    unsigned jmax = node->children.size();

    /*
        If this an usual letrec, not the program, then don't parse the last
        child element as an "in" expression.
    */
    if (!isProgram) jmax -= 1;

    _expr = 0;

    // Parse RDecls
    map<string, RDecl*> vars;
    for (j = 0; j < jmax; j++) {
        RDecl *rd = new RDecl(compiler, node->children.begin() + j);
        if (vars.insert(make_pair(rd->alias, rd)).second == false) {
            throw logic_error("Multiple declarations of \"" + rd->alias + "\".");
        }
        if (isProgram && compiler.testFlag(Compiler::OptimizeMain) && rd->alias == "main") {
            _expr = rd->expr;
        } else {
            _decls.push_back(rd);
        }
    }
    vars.clear(); // We're being very memory efficient here. Embedded here we come!

    if (isProgram) {
        if (!compiler.testFlag(Compiler::OptimizeMain)) {
            _expr = new IdentNode(compiler, "main");
        }
    } else {
        _expr = Node::nodeFactory(compiler, node->children.begin() + j);
    }
    assert(_expr != 0);

    // Optimize out unused declarations
    if (!_decls.empty() && compiler.testFlag(Compiler::OptimizeUnused)) {
        DEBUGMSG("Optimizing unused variables:");
        std::vector<RDecl*> decls(_decls);
        _decls.clear();
        unsigned n = decls.size();
        BoolMatrix b(n + 1, n + 1, false);
        for (unsigned c = 0; c < n; c++) {
            for (unsigned r = 0; r < n; r++) {
                if (decls.at(r)->expr->usesVariable(decls.at(c)->alias)) {
                    b.data[r][c] = true;
                }
            }
            if (_expr->usesVariable(decls.at(c)->alias)) {
                b.data[n][c] = true;
            }
        }
        b.transformToTransitiveClosure();
        #ifdef DEBUG
        unsigned unused = 0;
        #endif
        for (unsigned i = 0; i < n; i++) {
            if (b.data[n][i]) {
                _decls.push_back(decls.at(i));
            } else {
                DEBUGMSG("Found unused variable \"" + decls.at(i)->alias + "\" in letrec.");
                #ifdef DEBUG
                unused++;
                #endif
            }
        }
        DEBUGMSG("Found " + intToString(unused) + ".");
    }

    // Reorder cyclic definitions
    if (_decls.size() > 1 && compiler.testFlag(Compiler::OptimizeLetRecDecls)) {
        BoolMatrix b(_decls.size(), _decls.size(), true);
        for (unsigned c = 0; c < _decls.size(); c++) {
            for (unsigned r = 0; r < _decls.size(); r++) {
                if (c == r) {
                    b.data[r][r] = false; // Set identity values
                } else if (_decls.at(r)->expr->usesVariable(_decls.at(c)->alias)) {
                    b.data[r][c] = false;
                }
            }
        }
        unsigned n = _decls.size();
        vector<RDecl*> d(_decls);
        _decls.clear();
        unsigned *ds = new unsigned[n];
        for (unsigned i = 0; i < n; i++) ds[i] = i;
        MySort mySort(&b);
        stable_sort(ds, ds + n, mySort);
        for (unsigned i = 0; i < n; i++) _decls.push_back(d.at(ds[i]));
        delete ds;
    }
}
コード例 #9
0
ファイル: MyC.cpp プロジェクト: zzzbit/MyCpp
int main(int argc, char * argv[]){
	int a[5] = {234,456,23,78,12};
	mySort(a,5);
	return 0;
}
コード例 #10
0
void
beta::simulation_fast (parameters param)
{
  // Initializing the data structures
  vector < vector < miniPkt > >frontConnect;
  vector < list < miniPkt > >dds;

  //allocation memory for the data structures
  for (int i = 0; i < param.neuronNum; i++)
    {
      vector < miniPkt > temp;
      list < miniPkt > temp1;
      frontConnect.push_back (temp);
      dds.push_back (temp1);
    }


  // getting the connections in the forward direction
  for (int odr = 0; odr < param.order - 1; odr++)
    {
      for (int i = 0; i < betas[odr].size (); i++)
	{
	  for (int j = 0; j < betas[odr][i].size (); j++)
	    {
	      if (betas[odr][i][j].isConnection == true)
		{
		  for (int k = 0; k < betas[odr][i][j].parents.size (); k++)
		    {
		      int parent = betas[odr][i][j].parents[k];
		      int delay = betas[odr][i][j].delays[k];
		      bool flag = true;
		      int pos;
		      for (int chk = 0;
			   chk < frontConnect[parent - 1].size (); chk++)
			{
			  if (frontConnect[parent - 1][chk].event == i)
			    {
			      pos = chk;
			      flag = false;
			      break;
			    }
			}
		      miniPkt temp;
		      temp.event = i;
		      temp.time = delay;
		      if (flag == true)
			frontConnect[parent - 1].push_back (temp);
		      else
			frontConnect[parent - 1][pos] = temp;
		    }
		}
	    }
	}
    }
// FOR DEBUGGING
#if 0
  for (int i = 0; i < frontConnect.size (); i++)
    {
      displayMiniPkt (i, frontConnect[i]);
    }
#endif
  //SIMULATION BEGINS
  fstream out;
  out.open (param.outfile.c_str (), ios::out);
  int num = param.neuronNum;
  int nUpdates = int (param.teeSim / param.teeUpdate);
  readfile stimFile (param.stimulusFile);


  for (int i = 0; i < nUpdates; i++)
    {
      vector < miniPkt > events;
      //cout << "time: " << i*param.teeUpdate << endl;
      for (int j = 0; j < num; j++)
	{
	  //displayMiniPkt(j,dds[j]);
	  double voltage = param.theta;
	  list < miniPkt >::iterator nextIter;
	  for (int odr = 1; odr < param.order - 1; odr++)
	    {
	      for (int pkts = 0; pkts < betas[odr][j].size (); pkts++)
		{
		  bool addVoltage = true, parentThere;
		  for (int k = 0;
		       addVoltage == true
		       && k < betas[odr][j][pkts].parents.size (); k++)
		    {
		      int parent = betas[odr][j][pkts].parents[k];
		      parentThere = false;
		      for (list < miniPkt >::iterator listIter =
			   dds[j].begin (); listIter != dds[j].end ();
			   listIter++)
			{
			  if (i * param.teeUpdate == (*listIter).time
			      && (*listIter).event == parent - 1)
			    {
			      parentThere = true;
			      break;
			    }
			}
		      addVoltage = addVoltage * parentThere;
		    }
		  if (addVoltage == true)
		    voltage = voltage + betas[odr][j][pkts].beta;
		}
	    }
	  for (list < miniPkt >::iterator listIter = dds[j].begin ();
	       listIter != dds[j].end (); listIter = nextIter)
	    {
	      nextIter = ++listIter;
	      --listIter;
	      if (i * param.teeUpdate == (*listIter).time)
		{
		  voltage = voltage + betas[0][j][(*listIter).event].beta;
		  dds[j].erase (listIter);
		}
	    }
	  double spikeTime;
	  if (param.dist_flag == 0)
	    {
	      // getting a spiking time - with exponential distribution
	      spikeTime = getExpSpikeTime (param.lambdaM, voltage);
	    }
	  else if (param.dist_flag == 1)
	    {
	      spikeTime = getGamma2SpikeTime (param.lambdaM, voltage);
	    }
	  if (spikeTime < param.teeUpdate)
	    {
	      miniPkt spkie;
	      
		// check point : modifying the below line to reduce time resolution to param.teeUpdate
		// spkie.time = i*param.teeUpdate+spikeTime;
		spkie.time = i * param.teeUpdate;
	      spkie.event = j + 1;
	      events.push_back (spkie);
	      //updating the dds of the neurons that are affected by firing of 'j'
	      for (int w = 0; w < frontConnect[j].size (); w++)
		{
		  int nextevent = frontConnect[j][w].event;
		  double nextdelay = frontConnect[j][w].time;
		  miniPkt temp;
		  temp.time = (i + nextdelay) * param.teeUpdate;
		  temp.event = j;
		  dds[nextevent].push_back (temp);
		}
	    }
	}

      // Including External Spikes into the data stream :)

      int spike;
      while ((spike = stimFile.getnextevent ()) != -1)
	{
	  double spikeTime = stimFile.getTime ();
	  if (spikeTime < (i + 1) * param.teeUpdate)
	    {
	      miniPkt tempevent;
	      tempevent.time = spikeTime;
	      tempevent.event = spike;
	      //pushing into the data stream
	      events.push_back (tempevent);
	      //updating dds
	      for (int w = 0; w < frontConnect[spike - 1].size (); w++)
		{
		  int nextevent = frontConnect[spike - 1][w].event;
		  double nextdelay = frontConnect[spike - 1][w].time;
		  miniPkt temp;
		  temp.time = (i + nextdelay) * param.teeUpdate;
		  temp.event = spike - 1;
		  dds[nextevent].push_back (temp);
		}
	    }
	  else
	    {
	      stimFile.pushBackOne ();
	      break;
	    }
	}
      //Sorting based on time
      mySort (events);
      for (int x = 0; x < events.size (); x++)
	{
	  out << events[x].event << "," << events[x].time << endl;
	}
    }
}