Skip to content

[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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

itislu
Copy link
Collaborator

@itislu itislu commented Jun 7, 2024

  • 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.

@itislu itislu added the feature New feature of the project label Jun 7, 2024
@LeaYeh
Copy link
Owner

LeaYeh commented Jun 8, 2024

I think *_eff is really confused, why not just replace the logic?

@itislu
Copy link
Collaborator Author

itislu commented Jun 8, 2024

Because it requires a tail pointer as a third argument.
The caller has to provide that, which would require to add that parameter to all calls of ft_lstadd_back() and ft_lstnew_back().

@LeaYeh
Copy link
Owner

LeaYeh commented Jun 8, 2024

I see the interface change, but i will suggest you to use efficient but not the brief

@itislu itislu changed the title [LIB] Add ft_lstadd_back_eff(), ft_lstnew_back_eff() and ft_lstdup() to libft [LIB] Add new linked list functions to libft Jul 2, 2024
@itislu itislu force-pushed the lib-lstdup branch 3 times, most recently from 93bb7ce to 42c4c87 Compare July 5, 2024 14:21
LeaYeh
LeaYeh previously approved these changes Jul 9, 2024
@itislu itislu force-pushed the lib-lstdup branch 5 times, most recently from af2ea28 to b4ddecf Compare July 15, 2024 03:13
@itislu itislu marked this pull request as draft May 28, 2025 17:35
@itislu itislu marked this pull request as ready for review May 28, 2025 21:57
@itislu itislu requested a review from LeaYeh May 28, 2025 21:57
@itislu
Copy link
Collaborator Author

itislu commented May 28, 2025

I renamed the functions:

  • ft_lstadd_back_eff() -> ft_lstadd_back_tail()
  • ft_lstnew_back_eff() -> ft_lstnew_back_tail()

@itislu itislu added enhancement Enhancement of an existing feature and removed feature New feature of the project labels May 29, 2025
@itislu itislu requested a review from Copilot May 29, 2025 17:22
Copy link

@Copilot Copilot AI left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement of an existing feature
Projects
Status: Ready
Development

Successfully merging this pull request may close these issues.

2 participants