Classic DataStructures - z88dk/z88dk GitHub Wiki

Abstract data types

A container library modelled on C++'s STL containers. Header files are in

Non-Intrusive Containers Storing Copied Data

b_array

A fixed size array holding bytes. Modelled on C++ vector<char> but without the ability to expand. Can be used as wrapper on top of a statically allocated C-array. The library uses b_array in its terminal drivers to hold the edit buffer.

b_vector

A resizable array of bytes. Modelled on C++ vector<char>, just like the C++ type, b_vector can grow via realloc as needed. A max_size parameter can be specified to indicate a maximum size that any particular b_vector can grow to. The library uses b_vector to implement getdelim() and memstreams.

b_vector is implemented on top of b_array.

w_array

A fixed size array holding 16-bit words. Modelled on C++ vector<void*> but without the ability to expand. Provides the same functionality as b_array but for words.

w_array is implemented on top of b_array.

w_vector

A resizable array of words. Modelled on C++ vector<void*>, just like the C++ type, w_vector can grow via realloc as needed. A max_size parameter can be specified to indicate a maximum size that any particular w_vector can grow to. Provides the same functionality as b_vector but for words.

w_vector is implemented on top of b_vector.

ba_priority_queue, bv_priority_queue, wa_priority_queue, wv_priority_queue

A priority_queue storing either bytes (b*) or 16-bit words (w*). Modelled on C++ priority_queue<>, this type maintains items in heap order according to a user-supplied comparison function. Items can be extracted in order in O(lg n) time. The underlying container storing items is one of b_array, w_array, b_vector or w_vector. The vector containers allow growth via realloc while the array containers are static in size. Extracting all items from a priority_queue will leave the items stored in the underlying container in sorted order; this is an implementation of heapsort.

ba_stack, bv_stack, wa_stack, wv_stack

A stack storing either bytes (b*) or 16-bit words (w*) in LIFO order. Modelled on C++ stack<>, this data structure is a simple adapter of the underlying container functions. The underlying container storing the items is one of b_array, w_array, b_vector or w_vector. The vector containers allow growth via realloc while the array containers are static in size.

Intrusive Containers Storing References to User Data

User objects stored in these containers must supply space in their data structures for use by the container. The amount of space needed varies by container and can range from two bytes (singly linked list) to five bytes (red-black tree). Intrusive containers do not have to be concerned with memory allocation issues and this can both reduce their code size and speed up actions.

p_forward_list

A singly linked list of objects modelled on C++ forward_list<void*>. Objects stored in the list must have two bytes available to store next links.

Within clib, balloc (list of free memory blocks), stdio (list of FILE structures), and mutex (list of waiting threads) use p_forward_list.

p_forward_list_alt

A singly linked list of objects also modelled on C++ forward_list<void*> with the exception that adding an item to the end of the list can be done in O(1) time. Objects must have two bytes available to store next links. The cost is the p_forward_list_alt_t structure is four bytes compared to two for p_forward_list_t.

p_forward_list_alt is implemented on top of p_forward_list.

p_list

A doubly linked list of objects modelled on C++ list<void*>. Objects stored in the list must have four bytes available to store next and previous links.

p_list is implemented on top of p_forward_list.

p_queue

A container that stores objects in FIFO order. Items are pushed into the back of a queue and popped from the front. p_queue is modelled on C++ queue<void*>. Objects stored in the queue must have two bytes available to store next links.

p_queue is an adapter of p_forward_list_alt.

p_stack

A container that stores objects in LIFO order. p_stack is modelled on C++ stack<void*>. Objects in the stack must have two bytes available to store next links.

p_stack is an adapter of p_forward_list.

⚠️ **GitHub.com Fallback** ⚠️