コード例 #1
0
ファイル: fibheap.c プロジェクト: neesenk/heap
static void fibheap_consolidate(fibheap_t *fib)
{
	int i, max = 0;
	fibnode_t *tmp, *node, *min, *stack[1 + 8 * sizeof(long)] = {NULL};

	while ((min = fib->min) != NULL) {
		fib->min = fibnode_remove(min);
		for (i = min->degree; stack[i] != NULL; i++) {
			node = stack[i], stack[i] = NULL;
			if (min->key > node->key)
				tmp = min, min = node, node = tmp;

			fibheap_link(node, min);
		}
		stack[i] = min;
		if (i > max)
			max = i;
	}

	assert(max < 1 + 8 * sizeof(long));
	for (i = 0; i <= max; i++) {
		if (stack[i])
			__fibheap_insert(fib, stack[i]);
	}
}
コード例 #2
0
ファイル: fibheap.c プロジェクト: jeriksson/graphserver
/* Consolidate the heap.  */
static void
fibheap_consolidate (fibheap_t heap)
{
  fibnode_t a[1 + 8 * sizeof (long)];
  fibnode_t w;
  fibnode_t y;
  fibnode_t x;
  int i;
  int d;
  int D;

  D = 1 + 8 * sizeof (long);

  memset (a, 0, sizeof (fibnode_t) * D);

  while ((w = heap->root) != NULL)
    {
      x = w;
      fibheap_rem_root (heap, w);
      d = x->degree;
      while (a[d] != NULL)
	{
	  y = a[d];
	  if (fibheap_compare (heap, x, y) > 0)
	    {
	      fibnode_t temp;
	      temp = x;
	      x = y;
	      y = temp;
	    }
	  fibheap_link (heap, y, x);
	  a[d] = NULL;
	  d++;
	}
      a[d] = x;
    }
  heap->min = NULL;
  for (i = 0; i < D; i++)
    if (a[i] != NULL)
      {
	fibheap_ins_root (heap, a[i]);
	if (heap->min == NULL || fibheap_compare (heap, a[i], heap->min) < 0)
	  heap->min = a[i];
      }
}