Example #1
0
struct ServerBan *
SearchKlineTree(char *username, char *hostname)

{
  char host[HOSTLEN + 1];
  char **hostv;
  int hostc,
      ii;
  struct Level *ret;
  struct ServerBan *tmp;

  memset(host, 0, sizeof(host));
  strncpy_irc(host, hostname, HOSTLEN);

  hostc = BreakupHost(host, &hostv);

  if (!(++SerialNumber))
  {
    ++SerialNumber;
    ResetTree(&IlineTree);
    ResetTree(&KlineTree);
  }

  while ((ret = SearchSubTree(&KlineTree, hostc, hostv)))
  {
    if (!ret->numptrs)
    {
      log(L_ERROR,
        "SearchKlineTree(): search result has 0 Kline pointers");
      MyFree(hostv);
      /*ResetTree(&KlineTree);*/
      return (NULL);
    }

    /*
     * Check the username
     */
    for (ii = 0; ii < ret->numptrs; ++ii)
    {
      tmp = (struct ServerBan *) ret->typeptrs[ii];
      if (match(tmp->username, username))
      {
        MyFree(hostv);
        /*ResetTree(&KlineTree);*/
        return (tmp);
      }
    }
  }

  /*ResetTree(&KlineTree);*/

  /*
   * We failed to locate the Kline in our tree - search
   * the unsortable list
   */
  tmp = FindUnsortableKline(username, hostname);
  MyFree(hostv);
  return (tmp);
} /* SearchKlineTree() */
void CKDTree::ResetTree(KD_Node *parent)
{
	if(parent==NULL)
		return;
	parent->IsSearched=false;
	ResetTree(parent->m_left);
	ResetTree(parent->m_right);
}
//search the tree
void CKDTree::SearchTree(Point &p, float radius, ivector &vec_r)
{
	ResetTree(m_root);
	KD_Node *n=m_pRecentRoot;
	if (n==NULL)
	{
		n=m_root;
	}
	else
	{
		n=m_pRecentRoot;
		while(n!=m_root && !n->m_regOverlap.IsIn(p))
			n=n->m_parent;
	}
	while(n!=NULL && (n->m_left!=NULL || n->m_right!=NULL))
	{
		if (n->IsSplitX)
		{
			if(p.m_x<n->m_nMedian)
				n=n->m_left;
			else
				n=n->m_right;
		}
		else
		{
			if(p.m_y<n->m_nMedian)
				n=n->m_left;
			else
				n=n->m_right;
		}
	}
	m_pRecentRoot=n;
	SearchTree(n, p, radius, vec_r);
}
Example #4
0
void	quadsquare::StaticCullData(const quadcornerdata& cd, float ThresholdDetail)
// Examine the tree and remove nodes which don't contain necessary
// detail.  Necessary detail is defined as vertex data with a
// edge-length to height ratio less than ThresholdDetail.
{
    // First, clean non-static nodes out of the tree.
    ResetTree();

    // Make sure error values are up-to-date.
    if (Dirty) RecomputeError(cd);
	
    // Recursively check all the nodes and do necessary removal.
    // We must start at the bottom of the tree, and do one level of
    // the tree at a time, to ensure the dependencies are accounted
    // for properly.
    int	level;
    for (level = 0; level <= cd.Level; level++) {
	StaticCullAux(cd, ThresholdDetail, level);
    }
}
	void CKNearestNeighbor::Reset()
	{
		ResetTree();
		m_X.clear();
		m_Y.clear();
	}
Example #6
0
void MedianCut::BuildTree(CodeBook &Codes, long TreeSize)
{
bool bFinished = false;
TreeNode *pNode, *pLE, *pGT;
cbVector *pVect;
VectPtr *pList;
long Axis, Len, i, Split, Count, NumLeaves, Changed = 0;

	ResetTree();
	BuildRootNode(Codes);

	if(pRoot == 0)
		bFinished = true;

	NumLeaves = LeafList.Count();

	while(!bFinished)
	{
		pNode = GetFirstLeaf();

		Axis = pNode->LongAxis;
		Len = pNode->AxisLen;
		if(Len == 0) break;		// Couldn't find a split - Finished

		// Create two new tree nodes
		pLE = pNode->pLessEqual = GetNewTreeNode();
		pGT = pNode->pGreater = GetNewTreeNode();

		// Choose a split point for the parent node
		Split = pNode->SplitPoint;
		pNode->SplitAxis = (u8)Axis;
		pNode->SplitPoint = (u8)Split;

		// Move all nodes from the parent into the two children
		Count = pNode->CodeList.Count();
		pLE->CodeList.Resize(Count);
		pGT->CodeList.Resize(Count);

		pList = pNode->CodeList.Addr(0);
		for(i=0; i<Count; i++)
		{
			pVect = pList[i].pVect;

			if((*pVect)[Axis] <= Split)
				pLE->CodeList.Append(pList[i]);
			else
				pGT->CodeList.Append(pList[i]);
		}

		// Compute the min & max values of the two children
		pLE->ComputeBounds();
		pLE->ComputeError();

		pGT->ComputeBounds();
		pGT->ComputeError();

		pNode->CodeList.Resize(0);

		// Add the children to the leaf list and increment the leaf count
		LeafList.ExtractInsert( pLE );
		LeafList.Insert( pGT );
		NumLeaves++;

		if(NumLeaves == TreeSize)
			bFinished = true;
	}

	// Index the nodes
	Count = LeafList.Count();
	for(i=0; i<Count; i++)
	{
		pNode = GetLeaf(i);
		pNode->Index = i;
	}
}
Example #7
0
struct Iline *
SearchIlineTree(char *username, char *hostname)

{
  char host[HOSTLEN + 1];
  char **hostv;
  int hostc,
      ii;
  struct Level *ret;
  struct Iline *tmp;

  memset(host, 0, sizeof(host));
  strncpy_irc(host, hostname, HOSTLEN);

  hostc = BreakupHost(host, &hostv);

  /*
   * A loop is needed to continually search the IlineTree
   * because of the username problem. Suppose we have 2
   * Ilines:
   *    (a) foo@*.net
   *    (b)   *@*.underworld.net
   * and suppose the client comes from [email protected].
   * SearchSubTree() may return (a) since the hostname part
   * actually does match, but this routine will return NULL
   * because it cannot find a username match, even though
   * there is another I: line that matches. Therefore, this
   * loop will continue searching the tree until absolutely
   * no more hostname matches are found.
   *
   * We can be sure it will not return the same I: line twice
   * because the variable SerialNumber gets continually
   * incremented. When a node has been searched, it's
   * serial is set to the current SerialNumber variable, so
   * we know it has been searched if it's serial matches
   * SerialNumber.
   */

  if (!(++SerialNumber))
  {
    /*
     * SerialNumber will eventually roll over to 0 when it
     * reaches it's 32 bit limit - reset both trees and
     * increment SerialNumber to 1.
     */
    ++SerialNumber;
    ResetTree(&IlineTree);
    ResetTree(&KlineTree);
  }

  while ((ret = SearchSubTree(&IlineTree, hostc, hostv)))
  {
    if (!ret->numptrs)
    {
      log(L_ERROR,
        "SearchIlineTree(): search result has 0 Iline pointers");
      MyFree(hostv);
      /*ResetTree(&IlineTree);*/
      return (NULL);
    }

    /*
     * Now for the username check
     */
    for (ii = 0; ii < ret->numptrs; ++ii)
    {
      tmp = (struct Iline *) ret->typeptrs[ii];
      if (match(tmp->username, username))
      {
        MyFree(hostv);
        /*ResetTree(&IlineTree);*/
        return (tmp);
      }
    }
  }

  /*ResetTree(&IlineTree);*/

  /*
   * We failed to locate the Iline in our tree - search
   * the unsortable list
   */
  tmp = FindUnsortableIline(username, hostname);
  MyFree(hostv);
  return (tmp);
} /* SearchIlineTree() */