void CKDTree::SearchTree(KD_Node *parent, Point &p, float radius, ivector &vec_r)
{
	if (parent==NULL || parent->IsSearched)
		return;
	parent->IsSearched=true;
	//is a child node
	if(parent->m_left==NULL && parent->m_right==NULL)
	{
		int nSize=parent->m_vecIn.size();
		for (int i=0; i<nSize; ++i)
			if(m_regionArray[parent->m_vecIn[i]].IsSeen(p, radius))
				vec_r.push_back(parent->m_vecIn[i]);
	}
	//not a child node
	else
	{
		if(parent->m_left!=NULL && !parent->m_left->IsSearched && 
			(parent->m_left->m_regOverlap.IsSeen(p, radius)))
			SearchTree(parent->m_left, p, radius, vec_r);
		if (parent->m_right!=NULL && !parent->m_right->IsSearched &&
			(parent->m_right->m_regOverlap.IsSeen(p, radius)))
			SearchTree(parent->m_right, p, radius, vec_r);
	}
	//back trace : search parent
	SearchTree(parent->m_parent, p, radius, vec_r);
}
Ejemplo n.º 2
0
int checkword(char * str, strhash &htab, ivector &wcount, ivector &tokens, unhash &unh) {
  strtolower(str);
  int userno;
  if (htab.count(str)) {
    userno = htab[str];
    wcount[userno-1]++;
  } else {
    try {
      char * newstr = new char[strlen(str)+1];
      strcpy(newstr, str);
      wcount.push_back(1);
      unh.push_back(newstr);
      userno = unh.size();
      htab[newstr] = userno;
    } catch (bad_alloc) {
      cerr << "stringIndexer:checkstr: allocation error" << endl;
      throw;
    }
  }
  //  fprintf(stderr, "token %s (%d)\n", str, userno);
  tokens.push_back(userno);
  return userno;
}
Ejemplo n.º 3
0
int stringIndexer::
checkword(char * str) {
  int userno;
  char * newstr;
  if (htab.count(str)) {
    userno = htab[str];
    count[userno-1]++;
  } else {
    try {
      newstr = new char[strlen(str)+1];
      strcpy(newstr, str);
      userno = ++size;
      htab[newstr] = userno;
      count.push_back(1);
      unh.push_back(newstr);
    } catch (std::bad_alloc) {
      cerr << "stringIndexer:checkstr: allocation error" << endl;
      throw;
    }
  }
  return userno;
}
Ejemplo n.º 4
0
void addtok(int tok, ivector &tokens) {
  tokens.push_back(tok | 0x80000000);
}
Ejemplo n.º 5
0
int parseFormat(string ffname, ivector & tvec, svector & dnames, svector & delims, int *grpsize) {
  ifstream ifstr(ffname.c_str(), ios::in);
  if (ifstr.fail() || ifstr.eof()) {
    cerr << "couldnt open format file" << endl;
    throw;
  }
  char *next, *third, *newstr, *linebuf = new char[80];
  while (!ifstr.bad() && !ifstr.eof()) {
    ifstr.getline(linebuf, 80);
    if (strlen(linebuf) > 1) {
      next = strchr(linebuf, ' ');
      *next++ = 0;
      third = strchr(next, ' ');
      if (third)
	*third++ = 0;
      dnames.push_back(next);
      if (strncmp(linebuf, "int", 3) == 0) {
	tvec.push_back(ftype_int);
	delims.push_back("");
      } else if (strncmp(linebuf, "dint", 4) == 0) {
	tvec.push_back(ftype_dint);
	delims.push_back("");
      } else if (strncmp(linebuf, "qhex", 4) == 0) {
	tvec.push_back(ftype_qhex);
	delims.push_back("");
      } else if (strncmp(linebuf, "float", 5) == 0) {
	tvec.push_back(ftype_float);
	delims.push_back("");
      } else if (strncmp(linebuf, "double", 6) == 0) {
	tvec.push_back(ftype_double);
	delims.push_back("");
      } else if (strncmp(linebuf, "word", 4) == 0) {
	tvec.push_back(ftype_word);
	delims.push_back("");
      } else if (strncmp(linebuf, "string", 6) == 0) {
	tvec.push_back(ftype_string);
	ifstr.getline(linebuf, 80);
        newstr = new char[strlen(linebuf)+1];
        strcpy(newstr, linebuf);
	delims.push_back(newstr);
      } else if (strncmp(linebuf, "date", 4) == 0) {
	tvec.push_back(ftype_date);
	delims.push_back("");
      } else if (strncmp(linebuf, "mdate", 5) == 0) {
	tvec.push_back(ftype_mdate);
	delims.push_back("");
      } else if (strncmp(linebuf, "cmdate", 6) == 0) {
	tvec.push_back(ftype_cmdate);
	delims.push_back("");
      } else if (strncmp(linebuf, "dt", 2) == 0) {
	tvec.push_back(ftype_dt);
	delims.push_back("");
      } else if (strncmp(linebuf, "mdt", 3) == 0) {
	tvec.push_back(ftype_mdt);
	delims.push_back("");
      } else if (strncmp(linebuf, "group", 5) == 0) {
	sscanf(third, "%d", grpsize);
	tvec.push_back(ftype_group);
	delims.push_back("");
      } else if (strncmp(linebuf, "igroup", 6) == 0) {
	sscanf(third, "%d", grpsize);
	tvec.push_back(ftype_igroup);
	ifstr.getline(linebuf, 80);
	delims.push_back(linebuf);
      } else if (strncmp(linebuf, "digroup", 7) == 0) {
	sscanf(third, "%d", grpsize);
	tvec.push_back(ftype_digroup);
	ifstr.getline(linebuf, 80);
	delims.push_back(linebuf);
      } else {
        cerr << "couldnt parse format file line " << tvec.size()+1 << endl;
	throw;
      }
    }
  }
  return tvec.size();
  delete [] linebuf;
}