A high-performance, embeddable, and generic doubly linked list implementation in C. Designed for efficient and flexible integration into various data structures without the need for separate list nodes.
- Embeddable Design: Directly integrate
dll_tinto user-defined structures for seamless doubly linked list functionality. - Generic Implementation: Suitable for any data type, enhancing reusability and flexibility.
- Efficient Memory Usage: No additional allocations for list management, reducing memory overhead.
- Easy Traversal: Straightforward API for navigating through the list elements.
- A standard C compiler (e.g., GCC).
- Basic knowledge of C programming and data structures.
Clone the repository:
git clone https://github.com/harshithsunku/GenericEmbeddableDoublyLinkedList.git-
Include
dll_tin Your Structure:typedef struct { int data; // Your data dll_t link; // Embeddable list node } my_data_t;
-
Initialize the List:
dll_t my_list; dll_init(&my_list); // Initialize the list head
-
Add Elements to the List:
my_data_t element; dll_insert_after(&my_list, &element.link); // Insert element
-
Iterate Over the List:
printf("List contents:\n"); dll_t *iter; dll_traverse(&list_head, iter) { my_data_t *item = container_of(iter, my_data_t, link); printf("Data: %d\n", item->data); } my_data_t *temp; dll_traverse_entry(temp, &list_head, link, my_data_t){ printf("Data: %d\n", temp->data); }
-
Remove Elements:
dll_remove(&element.link); // Remove element from the list
Detailed API documentation is available in docs/api.md.
Contributions are welcome! Please read the contributing guidelines to get started.
This project is licensed under the GNU General Public License v3 (GPLv3).
- Thanks to all contributors and users of the GenericEmbeddableDoublyLinkedList project.