Exemplo n.º 1
0
int main(){
char str[]="abbbbbbbbbbcccaabbccaa";
printf("Original String  %s\n",str);
remove_duplicate(str);
printf("Pruned String  %s",str);

return 0;}
Exemplo n.º 2
0
int nfa2dfa(int start,int end)
 {
   int j,t,c,i,k,count,arr[10],name,l;
   for(i=start;i<=end;i++)
      {
    for(j=0;j<=max_inp;j++)
      {
        c=0;t=0;
        while(Fa[i][j][t]>=0)
           {
         t++;
         c++;
           }
        if(c>1)
        {
         if(check(i,j,c,&name)==0)
           {
             for(k=0;k<c;k++)
              {
             new_state[stat][k]=Fa[i][j][k];
             for(l=0;states[1][l]!=-1;l++)
                if(new_state[stat][k] == states[1][l]&& !search(stat))
                  states[1][no_stat++]=stat;
              }

              for(t=0;t<=max_inp;t++)
            {
               count=0;
               for(k=0;k<10;k++)
                  arr[k]=-1;
               trans(i,j,t,c,&count,arr);


               checkcon(arr,&count);

               sort(arr,count);
               remove_duplicate(arr,&count);

               for(k=0;k<count;k++)
                 Fa[stat][t][k]=arr[k];
            }
          Fa[i][j][0]=stat++;
          for(t=1;t<c;t++)
            Fa[i][j][t]=-1;
         }
           else
         {
           Fa[i][j][0]=name ;
           for(t=1;t<c;t++)
             Fa[i][j][t]=-1;
         }
          }//if(c>1) wala khatm hua
       }

     }
  return 0;
 }
int main(int argc,char* argv[]){
    //int start = atoi(argv[1]);
    //string str(argv[1]);
   	//string weekday(argv[2]);
    //float num = atof(argv[1]);	

	int x[] = {1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9};
	int len = sizeof(x)/sizeof(x[0]);
	vector<int> nums = getVector(x,len);
    remove_duplicate(nums);
    return 0;
}
Exemplo n.º 4
0
std::vector<xts::uri> fetch_image::chapter_getter::fetch_chapter_uri_all() const
{
   std::size_t image_index = 0;
   std::size_t size = _image_token.values.size();
   std::size_t batch_success_count = 1;
   std::string partial_url = source_token::remplace_token(_db.input.sources[_source_index], _number_token, _number_index);

   std::vector< xts::uri > image_uris;


   while (image_index < size && batch_success_count > 0)
   {
      std::vector< std::future< std::vector< xts::uri > > > image_uris_fetched;
      for (std::size_t i = 0; i < MAX_ERROR_ON_CHAPTER && image_index < size; ++i)
      {
         image_uris_fetched.emplace_back(std::async(
#ifdef _DEBUG
            std::launch::deferred,
#endif
            &chapter_getter::fetch_chapter_uri, this, astd::string_view(partial_url), image_index));
         ++image_index;
      }

      batch_success_count = 0;
      for (auto& image_uri_fetched : image_uris_fetched)
      {
         auto image_uri = image_uri_fetched.get();
         if (image_uri.size())
         {
            batch_success_count++;
            image_uris.insert(image_uris.end(), image_uri.begin(), image_uri.end());
         }
      }
   }

   image_uris = remove_duplicate(image_uris);
   return image_uris;
}
Exemplo n.º 5
0
/*
 * _bt_mergeload - Merge two streams of index tuples into new index files.
 */
static void
_bt_mergeload(Spooler *self, BTWriteState *wstate, BTSpool *btspool, BTReader *btspool2, Relation heapRel)
{
	BTPageState	   *state = NULL;
	IndexTuple		itup,
					itup2;
	bool			should_free = false;
	TupleDesc		tupdes = RelationGetDescr(wstate->index);
	int				keysz = RelationGetNumberOfAttributes(wstate->index);
	ScanKey			indexScanKey;
	ON_DUPLICATE	on_duplicate = self->on_duplicate;

	Assert(btspool != NULL);

	/* the preparation of merge */
	itup = BTSpoolGetNextItem(btspool, NULL, &should_free);
	itup2 = BTReaderGetNextItem(btspool2);
	indexScanKey = _bt_mkscankey_nodata(wstate->index);

	for (;;)
	{
		bool	load1 = true;		/* load BTSpool next ? */
		bool	hasnull;
		int32	compare;

		if (self->dup_old + self->dup_new > self->max_dup_errors)
			ereport(ERROR,
					(errcode(ERRCODE_INTERNAL_ERROR),
					 errmsg("Maximum duplicate error count exceeded")));

		if (itup2 == NULL)
		{
			if (itup == NULL)
				break;
		}
		else if (itup != NULL)
		{
			compare = compare_indextuple(itup, itup2, indexScanKey,
										 keysz, tupdes, &hasnull);

			if (compare == 0 && !hasnull && btspool->isunique)
			{
				ItemPointerData t_tid2;

				/*
				 * t_tid is update by heap_is_visible(), because use it for an
				 * index, t_tid backup
				 */
				ItemPointerCopy(&itup2->t_tid, &t_tid2);

				/* The tuple pointed by the old index should not be visible. */
				if (!heap_is_visible(heapRel, &itup->t_tid))
				{
					itup = BTSpoolGetNextItem(btspool, itup, &should_free);
				}
				else if (!heap_is_visible(heapRel, &itup2->t_tid))
				{
					itup2 = BTReaderGetNextItem(btspool2);
				}
				else
				{
					if (on_duplicate == ON_DUPLICATE_KEEP_NEW)
					{
						self->dup_old++;
						remove_duplicate(self, heapRel, itup2,
							RelationGetRelationName(wstate->index));
						itup2 = BTReaderGetNextItem(btspool2);
					}
					else
					{
						ItemPointerCopy(&t_tid2, &itup2->t_tid);
						self->dup_new++;
						remove_duplicate(self, heapRel, itup,
							RelationGetRelationName(wstate->index));
						itup = BTSpoolGetNextItem(btspool, itup, &should_free);
					}
				}

				continue;
			}
			else if (compare > 0)
				load1 = false;
		}
		else
			load1 = false;

		BULKLOAD_PROFILE(&prof_merge_unique);

		/* When we see first tuple, create first index page */
		if (state == NULL)
			state = _bt_pagestate(wstate, 0);

		if (load1)
		{
			IndexTuple	next_itup = NULL;
			bool		next_should_free = false;

			for (;;)
			{
				/* get next item */
				next_itup = BTSpoolGetNextItem(btspool, next_itup,
											   &next_should_free);

				if (!btspool->isunique || next_itup == NULL)
					break;

				compare = compare_indextuple(itup, next_itup, indexScanKey,
											 keysz, tupdes, &hasnull);
				if (compare < 0 || hasnull)
					break;

				if (compare > 0)
				{
					/* shouldn't happen */
					elog(ERROR, "faild in tuplesort_performsort");
				}

				/*
				 * If tupple is deleted by other unique indexes, not visible
				 */
				if (!heap_is_visible(heapRel, &next_itup->t_tid))
				{
					continue;
				}

				if (!heap_is_visible(heapRel, &itup->t_tid))
				{
					if (should_free)
						pfree(itup);

					itup = next_itup;
					should_free = next_should_free;
					next_should_free = false;
					continue;
				}

				/* not unique between input files */
				self->dup_new++;
				remove_duplicate(self, heapRel, next_itup,
								 RelationGetRelationName(wstate->index));

				if (self->dup_old + self->dup_new > self->max_dup_errors)
					ereport(ERROR,
							(errcode(ERRCODE_INTERNAL_ERROR),
							 errmsg("Maximum duplicate error count exceeded")));
			}

			_bt_buildadd(wstate, state, itup);

			if (should_free)
				pfree(itup);

			itup = next_itup;
			should_free = next_should_free;
		}
		else
		{
			_bt_buildadd(wstate, state, itup2);
			itup2 = BTReaderGetNextItem(btspool2);
		}
		BULKLOAD_PROFILE(&prof_merge_insert);
	}
	_bt_freeskey(indexScanKey);

	/* Close down final pages and write the metapage */
	_bt_uppershutdown(wstate, state);

	/*
	 * If the index isn't temp, we must fsync it down to disk before it's safe
	 * to commit the transaction.  (For a temp index we don't care since the
	 * index will be uninteresting after a crash anyway.)
	 *
	 * It's obvious that we must do this when not WAL-logging the build. It's
	 * less obvious that we have to do it even if we did WAL-log the index
	 * pages.  The reason is that since we're building outside shared buffers,
	 * a CHECKPOINT occurring during the build has no way to flush the
	 * previously written data to disk (indeed it won't know the index even
	 * exists).  A crash later on would replay WAL from the checkpoint,
	 * therefore it wouldn't replay our earlier WAL entries. If we do not
	 * fsync those pages here, they might still not be on disk when the crash
	 * occurs.
	 */
	if (!RELATION_IS_LOCAL(wstate->index))
	{
		RelationOpenSmgr(wstate->index);
		smgrimmedsync(wstate->index->rd_smgr, MAIN_FORKNUM);
	}
	BULKLOAD_PROFILE(&prof_merge_term);
}
Exemplo n.º 6
0
int main(int argc,char *argv[]){

    if( argc != 2){ //Check to see if enough arguments were given
        err_exit("ERROR: You did not give 1 arguments.");
    }

    int kid_count = atoi(argv[1]); //stores first argument as number of children to create

    char* token = NULL;
    int traffic_cop = 0;
    int length;
    int status;

    pid_t* sort_id = NULL;
    pid_t  supp_id;

    int** pipe_farm_ps = NULL; // fds for pipes for parent to sorts
    int** pipe_farm_sr = NULL; // fds for pipes for sorts to suppressor

    FILE** pp_ps = NULL; //pipe pointers for parent to sorts
    FILE** pp_sr = NULL; //pipe pointers for sorts to suppressor
    
    //Lock memory for pipes, pointers, and pids.
    sort_id = (pid_t*) malloc(sizeof(pid_t) * kid_count);
    pipe_farm_ps = (int**) malloc(sizeof(int*) * kid_count);
    pipe_farm_sr = (int**) malloc(sizeof(int*) * kid_count);
    pp_ps = (FILE**) malloc(sizeof(FILE*) * kid_count);
    pp_sr = (FILE**) malloc(sizeof(FILE*) * kid_count);

    token = (char*) malloc(sizeof(char) * MAX_TOKEN);



    for(int i = 0; i < kid_count; i++){
        
        pipe_farm_ps[i] =  malloc(sizeof(int) * 2);
        pipe_farm_sr[i] =  malloc(sizeof(int) * 2);

        if( pipe(pipe_farm_ps[i]) == -1 ) { //create pipes in pipe_farm_ps
            err_exit("ERROR: Problem creating pipe ps");
        }

        if((pp_ps[i] = fdopen(pipe_farm_ps[i][1],"w")) == NULL){
            err_exit("ERROR: Problem making pointer to pfdps.");
        }

        if( pipe(pipe_farm_sr[i]) == -1 ) { //create pipes in pipe_farm_sr
            err_exit("ERROR: Problem creating pipe sr");
        }

        if((pp_sr[i] = fdopen(pipe_farm_ps[i][1],"w")) == NULL){
            err_exit("ERROR: Problem making pointer to pfdsr.");
        }
    }
    
    for(int i = 0; i < kid_count; i++){ //Sorting kids
        if((sort_id[i] = fork()) == 0){

            for(int k = 0; k < kid_count; k++){
                if(i == k){
                    if(close(pipe_farm_ps[i][1]) != 0){
                        err_exit("ERROR: closing write end of pipe in child\n");
                    }
                    if(close(pipe_farm_sr[i][0]) != 0){
                        err_exit("ERROR: closing read end of pipe in child\n");
                    }
                    dup2(pipe_farm_ps[i][0], 0);
                    dup2(pipe_farm_sr[i][1], 1);
                }
                else{
                    if(close(pipe_farm_ps[k][1]) != 0){
                        err_exit("ERROR: closing write end of pipe in child\n");
                    }
                    if(close(pipe_farm_ps[k][0]) != 0){
                        err_exit("ERROR: closing read end of pipe in child\n");
                    }
                    if(close(pipe_farm_sr[k][1]) != 0){
                        err_exit("ERROR: closing write end of pipe in child\n");
                    }
                    if(close(pipe_farm_sr[k][0]) != 0){
                        err_exit("ERROR: closing read end of pipe in child\n");
                    }
                }
            }
            execl("/usr/bin/sort","sort",NULL); // make child into sort();
            _exit(1);
        }
    } // END Sorting kids
fflush(stdout);
    if((supp_id = fork()) == 0){ //Suppresor kid
        int sorters = kid_count;
        int* valid_sources = NULL;
        int token_count = 0;
        char* last_word = NULL;
        char** words = NULL;

        valid_sources = init_reader_table(sorters);
        words = (char**) malloc(sizeof(char*) * MAX_TOKEN);
        last_word = (char*) malloc(sizeof(char) * WORD_SIZE);

printf("LOLZ\n");
printf("%d%s\n",valid_sources[2],"Suppressor Check 1: \n");
        for(int i = 0; i < kid_count; i++){
            if(close(pipe_farm_ps[i][1]) != 0){
                err_exit("ERROR: closing write end of pipe in child\n");
            } 
            if(close(pipe_farm_ps[i][0]) != 0){
                err_exit("ERROR: closing read end of pipe in child\n");
            }
            if(close(pipe_farm_sr[i][1]) != 0){
                err_exit("ERROR: closing write end of pipe in child\n");
            }
            if((pp_sr[i] = fdopen(pipe_farm_sr[i][0], "r")) == NULL){
                err_exit("ERROR:creating file pointer from file descriptor suppressor\n");
            }
        }
printf("%s \n", "Suppressor Check 2: ");
        while(sorters > 0){
printf("%s \n", "Suppressor Check 3a: ");
            for(int i = 0; i < sorters; i++){
               traffic_cop = valid_sources[i];
printf("%d",traffic_cop);
printf("%s \n", "Suppressor Check 3b: ");

               if(fgets(token, WORD_SIZE , pp_sr[traffic_cop]) != NULL){
                   printf("%s \n", token);
                     if((length = strlen(token)) <= 2){
                     printf("%s \n","I AM HERE 1");
                        continue;
                    }
printf("%s \n", "Suppressor Check 3c: ");
                    if(token_count < MAX_TOKEN){
                        words[token_count] = (char*) malloc(sizeof(char) * (length + 1 ));
                        strcpy(words[token_count],token);
                        token_count++;
                        insert_sort(words, token_count);
                }
                    else{
                        token_count--;
                        if(strcmp(last_word, words[token_count]) != 0){
                            strcpy(last_word, words[token_count]);
                            printf("%s", words[token_count]);
                        }
                        token_count = remove_duplicate(words, token_count, words[token_count]);
                        length = strlen(words[token_count]);
                        strcpy(words[token_count], token);
                        token_count++;
                        insert_sort(words, token_count);
                    }
                }
                else{
                    printf("Kid dying: %d\n",traffic_cop);
                    sorters--;
                    remove_sorter(valid_sources,sorters,traffic_cop);
                }
            }
        }
printf("%s \n", "Suppressor Check 4: ");
        free(words);
        words = NULL;
        for(int i = 0; i < kid_count; i++){
            if(close(pipe_farm_sr[i][0]) != 0){
                err_exit("ERROR: closing pipe in suppressor");
            }
            free(pipe_farm_sr[i]);
            pipe_farm_sr[i] = NULL;
            free(pipe_farm_ps[i]);
            pipe_farm_ps[i] = NULL;
        }
        printf("%d",token_count);
        free(token);
        token = NULL;
        free(last_word);
        last_word = NULL;
        free(pp_sr);
        pp_sr = NULL;
        free(pp_ps);
        pp_ps = NULL;
        printf("Close Kid\n");
        _exit(EXIT_SUCCESS);
   } //END Supressor kid
fflush(stdout);

//Finish parent instructions
    while(fscanf(stdin,"%s",token) != EOF) {
        length = strlen(token);
        add_cr(token,length);
        lower_case(token, length);
        fputs(token, pp_ps[traffic_cop]);
printf("%s\n",token);
        if(traffic_cop == (kid_count - 1)){ // if we used last pipe, wrap around
            traffic_cop = -1;
        }
        traffic_cop++;
printf("%d",traffic_cop);
    } 
 
fflush(stdout);
    for(int i = 0; i < kid_count; i++){
        if(close(pipe_farm_ps[i][1]) != 0){
            err_exit("Error closing write end of pipe in parent\n");
        }
        if(close(pipe_farm_ps[i][0]) != 0){
            err_exit("Error closing read end of pipe in parent\n");
        }
        free(pipe_farm_ps[i]);
        free(pipe_farm_sr[i]);
    } 

    while (waitpid(-1,&status,WNOHANG) > 0){
        printf("Child exited");
    }
    free(token);
    token = NULL;
    free(pp_ps);
    pp_ps = NULL;
    free(pipe_farm_ps);
    free(pipe_farm_sr); 
    exit(EXIT_SUCCESS); 
}// END main
Exemplo n.º 7
0
int main()
{
    char str[] = "ababababababab";
    remove_duplicate(str);
    char *pt;
}