Example #1
0
void write_viminfo_filemarks(FILE *fp)
{
  int i;
  char_u      *name;
  buf_T       *buf;
  xfmark_T    *fm;

  if (get_viminfo_parameter('f') == 0)
    return;

  fputs(_("\n# File marks:\n"), fp);

  /*
   * Find a mark that is the same file and position as the cursor.
   * That one, or else the last one is deleted.
   * Move '0 to '1, '1 to '2, etc. until the matching one or '9
   * Set '0 mark to current cursor position.
   */
  if (curbuf->b_ffname != NULL && !removable(curbuf->b_ffname)) {
    name = buflist_nr2name(curbuf->b_fnum, TRUE, FALSE);
    for (i = NMARKS; i < NMARKS + EXTRA_MARKS - 1; ++i)
      if (namedfm[i].fmark.mark.lnum == curwin->w_cursor.lnum
          && (namedfm[i].fname == NULL
              ? namedfm[i].fmark.fnum == curbuf->b_fnum
              : (name != NULL
                 && STRCMP(name, namedfm[i].fname) == 0)))
        break;
    vim_free(name);

    vim_free(namedfm[i].fname);
    for (; i > NMARKS; --i)
      namedfm[i] = namedfm[i - 1];
    namedfm[NMARKS].fmark.mark = curwin->w_cursor;
    namedfm[NMARKS].fmark.fnum = curbuf->b_fnum;
    namedfm[NMARKS].fname = NULL;
  }

  /* Write the filemarks '0 - '9 and 'A - 'Z */
  for (i = 0; i < NMARKS + EXTRA_MARKS; i++)
    write_one_filemark(fp, &namedfm[i], '\'',
        i < NMARKS ? i + 'A' : i - NMARKS + '0');

  /* Write the jumplist with -' */
  fputs(_("\n# Jumplist (newest first):\n"), fp);
  setpcmark();          /* add current cursor position */
  cleanup_jumplist();
  for (fm = &curwin->w_jumplist[curwin->w_jumplistlen - 1];
       fm >= &curwin->w_jumplist[0]; --fm) {
    if (fm->fmark.fnum == 0
        || ((buf = buflist_findnr(fm->fmark.fnum)) != NULL
            && !removable(buf->b_ffname)))
      write_one_filemark(fp, fm, '-', '\'');
  }
}
Example #2
0
/*
 * Write all the named marks for all buffers.
 * Return the number of buffers for which marks have been written.
 */
int write_viminfo_marks(FILE *fp_out)
{
  int count;
  buf_T       *buf;
  int is_mark_set;
  int i;
  win_T       *win;
  tabpage_T   *tp;

  /*
   * Set b_last_cursor for the all buffers that have a window.
   */
  FOR_ALL_TAB_WINDOWS(tp, win)
  set_last_cursor(win);

  fputs(_("\n# History of marks within files (newest to oldest):\n"), fp_out);
  count = 0;
  for (buf = firstbuf; buf != NULL; buf = buf->b_next) {
    /*
     * Only write something if buffer has been loaded and at least one
     * mark is set.
     */
    if (buf->b_marks_read) {
      if (buf->b_last_cursor.lnum != 0)
        is_mark_set = TRUE;
      else {
        is_mark_set = FALSE;
        for (i = 0; i < NMARKS; i++)
          if (buf->b_namedm[i].lnum != 0) {
            is_mark_set = TRUE;
            break;
          }
      }
      if (is_mark_set && buf->b_ffname != NULL
          && buf->b_ffname[0] != NUL && !removable(buf->b_ffname)) {
        home_replace(NULL, buf->b_ffname, IObuff, IOSIZE, TRUE);
        fprintf(fp_out, "\n> ");
        viminfo_writestring(fp_out, IObuff);
        write_one_mark(fp_out, '"', &buf->b_last_cursor);
        write_one_mark(fp_out, '^', &buf->b_last_insert);
        write_one_mark(fp_out, '.', &buf->b_last_change);
        /* changelist positions are stored oldest first */
        for (i = 0; i < buf->b_changelistlen; ++i)
          write_one_mark(fp_out, '+', &buf->b_changelist[i]);
        for (i = 0; i < NMARKS; i++)
          write_one_mark(fp_out, 'a' + i, &buf->b_namedm[i]);
        count++;
      }
    }
  }

  return count;
}
Example #3
0
int max_removable(vector<vector<int> > neighbors, vector<int> cover) 
{ 
	int r=-1, max=-1; 
	for(int i=0; i<cover.size(); i++) 
	{ 
		if(cover[i]==1 && removable(neighbors[i],cover)==true) 
		{ 
			vector<int> temp_cover=cover; 
			temp_cover[i]=0; 
			int sum=0; 
			for(int j=0; j<temp_cover.size(); j++) 
				if(temp_cover[j]==1 && removable(neighbors[j], temp_cover)==true) 
					sum++; 
			if(sum>max) 
			{ 
				max=sum; 
				r=i; 
			} 
		} 
	} 
	return r; 
}
static void cleanupNode(Process::MessageNode& rootNode)
{
    for(auto it = rootNode.begin(); it != rootNode.end(); )
    {
        auto& child = *it;
        if(removable(child))
        {
            it = rootNode.erase(it);
        }
        else
        {
            it++;
        }
    }
}
Example #5
0
//  implementation of RE algorithm
bool REDiscard::reduceSpheres(Array<int> *inds, int maxNum, 
                               Array<int> *destCounts,
                               double maxMet, 
                               Array<double> *mets) const{
  //  get points
  const Array<Surface::Point> *surPts = surRep->getSurPts();
  int numPts = surPts->getSize();
  int numSph = srcSpheres->getSize();

  //  list of counts for number of spheres over each point
  Array<int> pointCounts(numPts), sphereCount(numSph);
  pointCounts.clear();

  //  fill list
  Array<bool> coveredPts(numPts);
  coveredPts.clear();
  for (int i = 0; i < numSph; i++){
    Array<int> list;
    surRep->listContainedPoints(&list, &coveredPts, srcSpheres->index(i));

    int numList = list.getSize(); 
    for (int j = 0; j < numList; j++){
      int pI = list.index(j);
      pointCounts.index(pI)++;
      }

    sphereCount.index(i) = numList;
    }

  //  no point continuing if the points aren't all covered to start
  for (int i = 0; i < numPts; i++)
    if (!coveredPts.index(i))
      return false;

  //  make list of spheres that are removable
  Array<bool> removable(numSph);
  for (int i = 0; i < numSph; i++)
    removable.index(i) = isSphereRemovable(pointCounts, i);  

  //  flags for which spheres have been dumped
  Array<bool> removed(numSph);
  removed.clear();

  //  do reduction
  while (true){
    //  find "smallest" removable sphere
    int minI = -1;
    int minCount = INT_MAX;
    for (int i = 0; i < numSph; i++){
      if (removable.index(i)){
        int count = sphereCount.index(i);
        if (count < minCount){
          minCount = count;
          minI = i;
          }
        }
      }

    //  did we find a removable sphere 
    if (minI < 0)
      break;

    OUTPUTINFO("Discarding Sphere %d\n", minI);

    //  remove sphere
    removed.index(minI) = true;
    removable.index(minI) = false;

    //  decrement counts for number of spheres covering the points
    Array<int> list;
    surRep->listContainedPoints(&list, NULL, srcSpheres->index(minI));
    int numList = list.getSize();
    for (int i = 0; i < numList; i++){
      int pI = list.index(i);
      pointCounts.index(pI)--;
      }
    
    //  check the spheres for removability
    for (int i = 0; i < numSph; i++){
      bool *flag = &removable.index(i);
      if ((*flag) == true){
        (*flag) = isSphereRemovable(pointCounts, i);  
        }
      }
    }

  //  generate indices
  inds->setSize(0);
  for (int i = 0; i < numSph; i++){
    if (!removed.index(i))
      inds->addItem() = i;
    }

  OUTPUTINFO("%d Spheres left\n", inds->getSize());

  return (maxNum < 0) || (inds->getSize() <= maxNum);
}