コード例 #1
0
static GCC_INLINE fcs_pats__insert_code_t insert_node(
    fcs_pats_thread_t * const soft_thread,
    fcs_pats__tree_t * const n,
    const int d,
    fcs_pats__tree_t ** const tree,
    fcs_pats__tree_t ** const node)
{
    const u_char * const key = (u_char *)n + sizeof(fcs_pats__tree_t);
    n->depth = d;
    n->left = n->right = NULL;
    *node = n;
    fcs_pats__tree_t *t = *tree;
    if (t == NULL) {
        *tree = n;
        return FCS_PATS__INSERT_CODE_NEW;
    }
    const typeof(soft_thread->bytes_per_pile) bytes_per_pile = soft_thread->bytes_per_pile;
    while (1) {
        const int c = compare_piles(bytes_per_pile, key, ((u_char *)t + sizeof(fcs_pats__tree_t)));
        if (c == 0) {
            break;
        }
        if (c < 0)
        {
            if (t->left == NULL) {
                t->left = n;
                return FCS_PATS__INSERT_CODE_NEW;
            }
            t = t->left;
        }
        else
        {
            if (t->right == NULL) {
                t->right = n;
                return FCS_PATS__INSERT_CODE_NEW;
            }
            t = t->right;
        }
    }

    /* We get here if it's already in the tree.  Don't add it again.
    If the new path to this position was shorter, record the new depth
    so we can prune the original path. */

    if (d < t->depth && !soft_thread->to_stack)
    {
        t->depth = d;
        *node = t;
        return FCS_PATS__INSERT_CODE_FOUND_BETTER;
    }
    else
    {
        return FCS_PATS__INSERT_CODE_FOUND;
    }
}
コード例 #2
0
ファイル: get_short_path.c プロジェクト: MarcBrout/Lemin
void		get_short_paths(t_larg *root)
{
  char		go;
  t_larg	*cur;

  go = 1;
  while (go)
    {
      cur = root->next;
      go = 0;
      while (cur != root && cur->next != root)
	{
	  if (cur->pile->next->room->id ==
	      cur->next->pile->next->room->id)
	    {
	      cur = compare_piles(root, cur, cur->next);
	      go = 1;
	    }
	  else
	    cur = cur->next;
	}
    }
}