-
Notifications
You must be signed in to change notification settings - Fork 197
Stdlib linked list #491
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
Stdlib linked list #491
Conversation
How should we review this patch best? While there is an implementation I don't find a specification, examples or tests in this PR.
Any update on this feature?
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.
This linked list is very good 👍 and can store almost any data type, I leave a little suggestion based on my limited knowledge, maybe not quite right :)
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.
It seems that the head and tail of the linked list need to be blanked here, otherwise an error will be reported when a new push node is pushed again.
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.
It seems that the destruction of the current node content should be added here.
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.
Maybe a routine can be abstracted here, allowing the user to customize the way to get the contents of the linked list?
... generic :: get => get_node_at_index, & get_node_at_index_user procedure, private :: get_node_at_index, & get_node_at_index_user ... abstract interface subroutine get_value(this_item, return_item) class(*), intent(in) :: this_item class(*), intent(out) :: return_item end subroutine get_value end interface ... subroutine get_node_at_index_user(this_list, node_index, func, return_item) class(child_list), intent(inout) :: this_list integer, intent(in) :: node_index procedure(get_value) :: func class(*), intent(out) :: return_item type(node), pointer :: curr_node integer index curr_node => this_list%head index = 1 do while (associated(curr_node)) if (index == node_index) then call func(curr_node%item, return_item) nullify (curr_node) return end if curr_node => curr_node%next index = index + 1 end do nullify (curr_node) end subroutine get_node_at_index_user ...
The user can use it like this:
program main use linked_list_m, only: child_list, rk, ik implicit none real(rk) :: x integer(ik) :: n type(this_child) :: list print *, list%size() call list%push(1.0_rk) call list%push(2_ik) call list%get(1, get_value, x) call list%get(2, get_value, n) print *, x, n, list%size() contains subroutine get_value(this_item, return_item) class(*), intent(in) :: this_item class(*), intent(out) :: return_item select type (this_item) type is (real(rk)) select type (return_item) type is (real(rk)) return_item = this_item class default print *, '*<ERROR>* get_value: type mismatch' end select type is (integer(ik)) select type (return_item) type is (integer(ik)) return_item = this_item class default print *, '*<ERROR>* get_value: type mismatch' end select class default print *, "*<ERROR>* get_value: invalid type" end select end subroutine get_value end program main
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
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.
source uses the optional argument new_item here, there may be memory access errors.
I guess this PR has become stale. Since we already have a decent implementation here, should we try to update the PR, address the review comments and get it merged?
I guess this PR has become stale. Since we already have a decent implementation here, should we try to update the PR, address the review comments and get it merged?
Maybe @arjenmarkus / @chetan has some news/updates. Specs and tests are mainly missing.
I have (finally, sigh ;)) started setting up a test program. The documentation will follow with it.
This PR is to submit the first draft of the linked list module for stdlib.
This is based upon #68 by Milan, #463 by me.
I have been working on this module as a part of my GSoC Project.
All my work was regularly updated on my personal repository that I have been sharing with everyone in my weekly report.
Link to my repository (here).
A bit detailed project report is available (here).
List of all the weekly Blogs - (here)
The module was tested in two compilers, intel oneAPI and gfortran.