55 static void quick_sort(
void *blocks_array,
size_t num_blocks,
size_t block_size,
short int (*cmp_func)(
const void *,
const void *));
56 static void rec_quick_sort(
void *blocks_array[], U16BIT left, U16BIT right,
short int (*cmp_func)(
const void *,
const void *));
92 new_blk->next = next_blk;
93 new_blk->prev = prev_blk;
96 *prev_blk_next_ptr = new_blk;
99 *next_blk_prev_ptr = new_blk;
123 hdr->null_next = NULL;
172 ASSERT(cmp_func != NULL);
173 ASSERT(ll_hdr != NULL);
183 if (blocks_array == NULL)
191 for (i = 0; i < num_blocks; i++)
193 ASSERT(ll_block != NULL);
194 blocks_array[i] = ll_block;
201 ASSERT(ll_block == NULL);
203 ASSERT(
sizeof(
size_t) ==
sizeof(U32BIT));
210 quick_sort((
void *)blocks_array, (
size_t)num_blocks, (
size_t)block_size, (
short int (*)(
const void *,
const void *))cmp_func);
213 for (i = 0; i < num_blocks; i++)
241 static void quick_sort(
void *blocks_array,
size_t num_blocks,
size_t block_size,
short int (*cmp_func)(
const void *,
const void *))
244 USE_UNWANTED_PARAM(block_size);
247 rec_quick_sort((
void **)blocks_array, 0, (U16BIT)(num_blocks - 1), cmp_func);
267 static void rec_quick_sort(
void *blocks_array[], U16BIT left, U16BIT right,
short int (*cmp_func)(
const void *,
const void *))
269 register U16BIT i, j;
279 temp = blocks_array[left];
284 for (; ((j > left) && (cmp_func(&blocks_array[j], &temp) > 0)); j--)
287 for (blocks_array[i] = blocks_array[j]; ((i < j) && cmp_func(&blocks_array[i], &temp) <= 0); i++)
290 blocks_array[j] = blocks_array[i];
292 blocks_array[i] = temp;
295 if ((i - left) < (right - i))
297 rec_quick_sort(blocks_array, left, (U16BIT)i, cmp_func);
302 rec_quick_sort(blocks_array, (U16BIT)(i + 1), right, cmp_func);
333 ASSERT(new_blk != NULL);
336 prev_blk = hdr->last;
340 if (prev_blk->next == NULL)
372 ASSERT(new_blk != NULL);
375 next_blk = hdr->first;
379 if (next_blk->next == NULL)
410 ASSERT(next_blk != NULL);
411 ASSERT(new_blk != NULL);
415 prev_blk = next_blk->prev;
419 if (prev_blk->next == NULL)
429 InsertBlkInList(prev_blk, new_blk, next_blk, prev_blk_next_ptr, (
LINK_LIST_PTR_BLK **)&(next_blk->prev));
454 ASSERT(prev_blk != NULL);
455 ASSERT(new_blk != NULL);
458 next_blk = prev_blk->next;
462 if (next_blk->next == NULL)
472 InsertBlkInList(prev_blk, new_blk, next_blk, (
LINK_LIST_PTR_BLK **)&(prev_blk->next), next_blk_prev_ptr);
500 prev_blk = blk->prev;
501 if (prev_blk != NULL)
505 if (prev_blk->next == NULL)
516 prev_blk_next_ptr = NULL;
520 next_blk = blk->next;
521 if (next_blk != NULL)
525 if (next_blk->next == NULL)
536 next_blk_prev_ptr = NULL;
539 if (prev_blk_next_ptr != NULL)
542 *prev_blk_next_ptr = next_blk;
545 if (next_blk_prev_ptr != NULL)
548 *next_blk_prev_ptr = prev_blk;
575 next_blk = blk->next;
579 if (next_blk->next == NULL)
609 prev_blk = blk->prev;
613 if (prev_blk->next == NULL)
642 next_blk = hdr->first;
645 if (next_blk->next == NULL)
674 prev_blk = hdr->last;
677 if (prev_blk->next == NULL)
712 while ((next_blk != NULL) && (i < num))
750 while (next_blk != NULL)
787 while (next_blk != NULL)
U16BIT STB_LLGetNumBlocks(LINK_LIST_HEADER *hdr)
Counts and returns the number of blocks in a linked list.
void * STB_GetMemory(U32BIT bytes)
Attempts to allocate memory from the heap.
BOOLEAN STB_LLCheckBlockInList(LINK_LIST_HEADER *hdr, LINK_LIST_PTR_BLK *blk)
Checks if the supplied pointer is to a block in the specified list.
void STB_LLRemoveBlock(LINK_LIST_PTR_BLK *blk)
Removes the block identified by the blk pointer from its linked list.
LINK_LIST_PTR_BLK * STB_LLGetLastBlock(LINK_LIST_HEADER *hdr)
Returns a pointer to the last block in the linked list, identified by hdr.
void STB_LLAddBlockBefore(LINK_LIST_PTR_BLK *next_blk, LINK_LIST_PTR_BLK *new_blk)
Adds the block identified by the new_blk pointer to the linked list before the block identified by th...
void STB_LLAddBlockToEnd(LINK_LIST_HEADER *hdr, LINK_LIST_PTR_BLK *new_blk)
Adds the block identified by the new_blk pointer to the end of the linked list identified by the list...
void STB_FreeMemory(void *addr)
Releases previously allocated heap memory.
void STB_LLInitialiseHeader(LINK_LIST_HEADER *hdr)
Initialise the header variables of the linked list.
Debug functions header file.
Header file - Function prototypes for linked lists.
System Wide Global Technical Data Type Definitions.
void STB_LLAddBlockToStart(LINK_LIST_HEADER *hdr, LINK_LIST_PTR_BLK *new_blk)
Adds the block identified by the new_blk pointer to the start of the linked list identified by the li...
BOOLEAN STB_LLSort(LINK_LIST_HEADER *ll_hdr, S16BIT(*cmp_func)(LINK_LIST_PTR_BLK **, LINK_LIST_PTR_BLK **))
Sorts the blocks of a link list object in ascending or descending order NOTE: The order in which the ...
Header file - Function prototypes for heap memory.
LINK_LIST_PTR_BLK * STB_LLGetFirstBlock(LINK_LIST_HEADER *hdr)
Returns a pointer to the first block in the linked list, identified by hdr.
void STB_LLAddBlockAfter(LINK_LIST_PTR_BLK *prev_blk, LINK_LIST_PTR_BLK *new_blk)
Adds the block identified by the new_blk pointer to the linked list after the block identified by the...
LINK_LIST_PTR_BLK * STB_LLGetPrevBlock(LINK_LIST_PTR_BLK *blk)
Returns a pointer to the previous block in the linked list, or NULL if at the start of the list...
LINK_LIST_PTR_BLK * STB_LLGetBlock(LINK_LIST_HEADER *hdr, U16BIT num)
Returns a pointer to the n-th block in the list.
LINK_LIST_PTR_BLK * STB_LLGetNextBlock(LINK_LIST_PTR_BLK *blk)
Returns a pointer to the next block in the linked list, or NULL if at the end of the list...