1 Star 1 Fork 0

清风徐来 / 单向链表

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Singly Linked List

Language 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:

[dependencies]
slinked-list = { git="https://github.com/zoziha/slinked-list" }

Example

> fpm run --example --all  # run the example
program main

    use 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 pointer

    call 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 select

        end 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 memory

end 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

MIT License Copyright (c) 2022-2023 ZUO Zhihua Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

🏓`slinked_list`: Replica of the Fortran standard library linked list container. 展开 收起
FORTRAN
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
FORTRAN
1
https://gitee.com/zoziha/slinked-list.git
git@gitee.com:zoziha/slinked-list.git
zoziha
slinked-list
单向链表
main

搜索帮助