Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zoziha/slinked-list
Simple generic singly linked list module for in-memory storage of small amounts of data.
https://github.com/zoziha/slinked-list
fortran fortran-package-manager linked-list singly-linked-list
Last synced: 25 days ago
JSON representation
Simple generic singly linked list module for in-memory storage of small amounts of data.
- Host: GitHub
- URL: https://github.com/zoziha/slinked-list
- Owner: zoziha
- License: mit
- Created: 2023-07-27T10:07:17.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-07-27T13:30:14.000Z (over 1 year ago)
- Last Synced: 2023-07-27T14:50:26.890Z (over 1 year ago)
- Topics: fortran, fortran-package-manager, linked-list, singly-linked-list
- Language: Fortran
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Singly Linked List
![Language](https://img.shields.io/badge/-Fortran-734f96?logo=fortran&logoColor=white)
[![license](https://img.shields.io/badge/License-MIT-pink)](LICENSE)Simple generic singly linked list module for in-memory storage of small amounts of data. `sll` provides the ability to reuse linked list space to avoid the time-consuming duplication of memory allocation and destruction in certain application scenarios.
*Suggestions and code contributions are welcome.*
## Usage
Only FPM is supported, other build systems can copy source files directly,
and `ifort/ifx` and `gfortran` compilers are tested.To use `slinked-list` within your `fpm` project, add the following lines to your `fpm.toml` file:
```toml
[dependencies]
slinked-list = { git="https://github.com/zoziha/slinked-list" }
```## Example
```sh
> fpm run --example --all # run the example
``````fortran
program mainuse sll_module, only: sll, iterator, sll_storage, sll_finalizer, iterator_finalizer
use display_module, only: display
implicit none
type(sll) :: list !! singly linked list
type(iterator) :: iter !! iterator for sll
class(*), pointer :: ptr !! generic pointercall list%push_back(1.0)
call list%push_back(2)
call display(list%size(), "size:", inline=.true.)
call display(list%size(.true.), "capacity:", inline=.true.)call list%empty()
call list%push_back(3.0)
call display(list%size(), "size:", inline=.true.)
call display(list%size(.true.), "capacity:", inline=.true.)if (.not. list%is_empty()) then
iter = iterator(list)
do while (iter%next(ptr))select type (ptr)
type is (real)
call display(ptr, "v:", inline=.true.)
type is (integer)
call display(ptr, "v:", inline=.true.)
end selectend do
end if
call display(sll_storage(list) + storage_size(list), "storage size (bit):", inline=.true.)
call sll_finalizer(list) ! free memory
call iterator_finalizer(iter) ! free memoryend program main
!> [scalar] size: 2
!> [scalar] capacity: 2
!> [scalar] size: 1
!> [scalar] capacity: 2
!> [scalar] v: 3.000E+00
!> [scalar] storage size (bit): 1664
```Note: Due to the type conversion of `class(*)`, `sll` is not efficient, so it is only used for storing small datasets.
## Link
- [zoziha/dlinked_list](https://gitee.com/zoziha/dlinked_list)
- [fortran-lang/stdlib](https://github.com/fortran-lang/stdlib)
- [浅谈单链表与双链表的区别](https://blog.csdn.net/kangxidagege/article/details/80211225)