Exemple #1
0
Fichier : heap.c Projet : kcyeu/xcb
static void heap_swap(heap_t heap, unsigned long i, unsigned long j) {
	void *tmp;

	tmp = heap_get(heap, i);
	heap_set(heap, i, heap_get(heap, j));
	heap_set(heap, j, tmp);
}
Exemple #2
0
static inline void heap_swap(struct ast_heap *h, int i, int j)
{
	void *tmp;

	tmp = heap_get(h, i);
	heap_set(h, i, heap_get(h, j));
	heap_set(h, j, tmp);
}
Exemple #3
0
	bool EnableLowFragmentationHeap() {
		HMODULE kernel32 = GetModuleHandle(L"kernel32.dll");
		HeapSetFn heap_set = reinterpret_cast<HeapSetFn>(GetProcAddress(
			kernel32,
			"HeapSetInformation"));

		// On Windows 2000, the function is not exported. This is not a reason to
		// fail.
		if (!heap_set)
			return true;

		unsigned number_heaps = GetProcessHeaps(0, NULL);
		if (!number_heaps)
			return false;

		// Gives us some extra space in the array in case a thread is creating heaps
		// at the same time we're querying them.
		static const int MARGIN = 8;
		scoped_ptr<HANDLE[]> heaps(new HANDLE[number_heaps + MARGIN]);
		number_heaps = GetProcessHeaps(number_heaps + MARGIN, heaps.get());
		if (!number_heaps)
			return false;

		for (unsigned i = 0; i < number_heaps; ++i) {
			ULONG lfh_flag = 2;
			// Don't bother with the result code. It may fails on heaps that have the
			// HEAP_NO_SERIALIZE flag. This is expected and not a problem at all.
			heap_set(heaps[i],
				HeapCompatibilityInformation,
				&lfh_flag,
				sizeof(lfh_flag));
		}
		return true;
	}
Exemple #4
0
Fichier : heap.c Projet : kcyeu/xcb
/* Return 0 if success, otherwise -1 is returned */
int heap_push(heap_t heap, void *elem) {
	if (heap == NULL || elem == NULL)
		return -1;
	if (heap->curr == heap->avail && grow_heap(heap))
		return -1;
	heap_set(heap, ++heap->curr, elem);
	bubble_up(heap, heap->curr);
	return 0;
}
Exemple #5
0
Fichier : heap.c Projet : kcyeu/xcb
static void *_heap_remove(heap_t heap, unsigned long i) {
	void *ret;

	if (i > heap->curr)
		return NULL;
	ret = heap_get(heap, i);
	heap_set(heap, i, heap_get(heap, heap->curr--));
	i = bubble_up(heap, i);
	max_heapify(heap, i);
	return ret;
}
Exemple #6
0
void* heap_extract_min(Heap* heap) {
  void* min = heap_min(heap);

  if(heap_size(heap) > 0) {
    heap_set(heap, 0, heap_last(heap));
    heap_bubble_down(heap, 0);
  }

  heap->size--;

  return min;
}
Exemple #7
0
void heap_insert(Heap* heap, void* value) {
  if(heap_capacity(heap) * HEAP_LOAD_FACTOR <= heap_size(heap)) {
    heap_resize(heap);
  }

  unsigned int next_index = heap_last_index(heap) + 1;

  heap_set(heap, next_index, value);

  heap->size++;
  
  heap_bubble_up(heap, next_index);
}
Exemple #8
0
static void *_ast_heap_remove(struct ast_heap *h, unsigned int index)
{
	void *ret;

	if (!index || index > h->cur_len) {
		return NULL;
	}

	ret = heap_get(h, index);
	heap_set(h, index, heap_get(h, (h->cur_len)--));
	index = bubble_up(h, index);
	max_heapify(h, index);

	return ret;
}
Exemple #9
0
void *heap_remove(heap_t *h, int k) {
    void *data;

    if (k >= h->len) {
        return NULL;
    }

    data = h->data[k];
    --h->len;
    heap_set(h, k, h->data[h->len]);
    heap_siftdown(h, k);
    heap_siftup(h, k);
    if (h->record) {
        h->record(data, -1);
    }
    return data;
}
Exemple #10
0
int ast_heap_push(struct ast_heap *h, void *elm)
#endif
{
	if (h->cur_len == h->avail_len && grow_heap(h
#ifdef MALLOC_DEBUG
		, file, lineno, func
#endif
		)) {
		return -1;
	}

	heap_set(h, ++(h->cur_len), elm);

	bubble_up(h, h->cur_len);

	return 0;
}
Exemple #11
0
/* heap_insert insert `data' into heap `h' according
 * to h->less.
 * 0 returned on success, otherwise -1. */
int heap_insert(heap_t *h, void *data) {
    int k;

    if (h->len >= h->cap) {
        void **ndata;
        int ncap = (h->len + 1) * 2; /* callocate twice what we need */

        ndata = realloc(h->data, sizeof(void*) * ncap);
        if (!ndata) {
            return -1;
        }
        h->data = ndata;
        h->cap = ncap;
    }
    k = h->len;
    ++h->len;
    heap_set(h, k, data);
    heap_siftdown(h, k);
    return 0;
}
Exemple #12
0
int ast_heap_push(struct ast_heap *h, void *elm)
#endif
{
	int i;

	if (h->cur_len == h->avail_len && grow_heap(h
#ifdef MALLOC_DEBUG
		, file, lineno, func
#endif
		)) {
		return -1;
	}

	heap_set(h, ++(h->cur_len), elm);

	for (i = h->cur_len;
			i > 1 && h->cmp_fn(heap_get(h, parent_node(i)), heap_get(h, i)) < 0;
			i = parent_node(i)) {
		heap_swap(h, i, parent_node(i));
	}

	return 0;
}
Exemple #13
0
static void heap_swap(heap_t *h, int a, int b) {
    void *tmp;
    tmp = h->data[a];
    heap_set(h, a, h->data[b]);
    heap_set(h, b, tmp);
}
Exemple #14
0
void heap_swap(Heap* heap, int index0, int index1) {
  void* temp = heap_get(heap, index0);
  heap_set(heap, index0, heap_get(heap, index1));
  heap_set(heap, index1, temp);
}