-
Notifications
You must be signed in to change notification settings - Fork 3
[LIB] Add new linked list functions to libft #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I think *_eff is really confused, why not just replace the logic? |
Because it requires a tail pointer as a third argument. |
I see the interface change, but i will suggest you to use efficient but not the brief |
ft_lstadd_back_eff()
, ft_lstnew_back_eff()
and ft_lstdup()
to libft93bb7ce
to
42c4c87
Compare
af2ea28
to
b4ddecf
Compare
I renamed the functions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces new tail-pointer optimized functions for singly linked lists and adds a doubly linked list sizing function to improve performance and functionality in libft.
- Introduces ft_lstadd_back_tail() and ft_lstnew_back_tail() to avoid list traversal when appending nodes.
- Adds ft_lstdup() for duplicating singly linked lists and ft_lstsize_d() for computing the size of doubly linked lists.
- Updates header files and build scripts to integrate these new functions.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
libraries/libft/src/lists/singly_linked/ft_lstnew_front.c | Added NULL check for lst and updated function documentation. |
libraries/libft/src/lists/singly_linked/ft_lstnew_back_tail.c | Added new tail-pointer based node creation function. |
libraries/libft/src/lists/singly_linked/ft_lstnew_back.c | Added NULL check for lst and updated documentation accordingly. |
libraries/libft/src/lists/singly_linked/ft_lstmap.c | Updated to use the new ft_lstadd_back_tail() for tail-based appending. |
libraries/libft/src/lists/singly_linked/ft_lstdup.c | Added new function to duplicate a list using tail-pointer methods. |
libraries/libft/src/lists/singly_linked/ft_lstadd_back_tail.c | Introduced new function to add a node with tail pointer updates. |
libraries/libft/src/lists/doubly_linked/ft_lstsize_d.c | Introduced new function to compute the size of a doubly linked list. |
libraries/libft/inc/libft.h | Updated header with prototypes for new functions. |
libraries/libft/build/libft.mk | Updated build file to include new source files. |
ft_lstadd_back_eff()
ft_lstadd_back_tail()
ft_lstnew_back_eff()
ft_lstnew_back_tail()
ft_lstdup()
ft_lstsize_d()
The efficient versions of
ft_lstadd_back
expect a tail pointer of the list to avoid traversing the whole list.I made those function in an older, unmerged branch in February already.