SHARE
TWEET

Untitled

a guest Sep 18th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int loners(char* folder) {
  2.     printf("removing loners \n");
  3.  
  4.     mutperson_map = (optimizedPerson *)         mmapr(makepath(folder, "mutual_persons",   "bin"), &person_length);
  5.     mutknows_map = (unsigned int *)   mmapr(makepath(folder, "mutual_knows",    "bin"), &knows_length);
  6.     interests_map = (unsigned short *) mmapr(makepath(folder, "interest", "bin"), &interests_length);
  7.  
  8.     int interests_counter = 0;
  9.     unsigned long knows_offset, interests_offset;
  10.  
  11.     unsigned int person_offset, person_new_offset;
  12.     int *offset_tracker = malloc(person_length/sizeof(optimizedPerson) * sizeof(int));
  13.  
  14.     // Files
  15.     char* noloner_persons_file = makepath(folder, "noloner_persons", "bin");
  16.     char* noloner_knows_file = makepath(folder, "noloner_knows", "bin");
  17.     char* noloner_interests_file = makepath(folder, "noloner_interests", "bin");
  18.  
  19.     remove(noloner_persons_file);
  20.     remove(noloner_knows_file);
  21.     remove(noloner_interests_file);
  22.  
  23.     noloner_persons = fopen(noloner_persons_file, "a");
  24.     noloner_knows = fopen(noloner_knows_file, "a");
  25.     noloner_interests = fopen(noloner_interests_file, "a");
  26.  
  27.     // Filtering friendless people
  28.    
  29.     // Loop over all persons, keep track of new offsets based on knows_n > 0  in an array
  30.     for (person_offset = person_new_offset = 0; person_offset < person_length/sizeof(optimizedPerson); person_offset++) {
  31.         locperson = &mutperson_map[person_offset];
  32.         if(locperson->knows_n > 0) {
  33.             offset_tracker[person_offset] = person_new_offset;
  34.             person_new_offset++;
  35.         } else {
  36.             offset_tracker[person_offset] = -1;
  37.         }
  38.     }
  39.  
  40.     // Loop over all persons
  41.     // counters for knows and interests firsts
  42.     for (person_offset = person_new_offset = 0; person_offset < person_length/sizeof(optimizedPerson); person_offset++) {
  43.         locperson = &mutperson_map[person_offset];
  44.         // als in array -1, continue
  45.         if (offset_tracker[person_offset] == -1) {
  46.             continue;
  47.         } else{
  48.             // - for vrienden van die persoon, schrijf de juiste offsets op, adjust teller
  49.             for (knows_offset = locperson->knows_first;
  50.             knows_offset < locperson->knows_first + locperson->knows_n;
  51.             knows_offset++) {
  52.                 fwrite(&offset_tracker[mutknows_map[knows_offset]], sizeof(unsigned int), 1, noloner_knows);
  53.             }
  54.             // - for for interests van die persoon, schrijf de juiste first op, adjust teller
  55.             locperson->interests_first = interests_counter;  
  56.             for (interests_offset = locperson->interests_first;
  57.                 interests_offset < locperson->interests_first + locperson->interest_n;
  58.                 interests_offset++) {
  59.                 //fwrite(&interests_map[interests_offset], sizeof(unsigned short),1, noloner_interests);
  60.                 //interests_counter++;
  61.             }
  62.         }
  63.     }
  64.  
  65.     // Closing up
  66.     fclose(noloner_persons);
  67.     fclose(noloner_knows);
  68.    
  69.     return 0;
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top