Giter Site home page Giter Site logo

jchristopherson / collections Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 278 KB

A set of types supporting collections in Fortran.

License: GNU General Public License v3.0

CMake 8.36% Fortran 91.64%
collection collections fortran linked-list list lists generic-collections generic-list

collections's Introduction

collections

A set of types supporting collections in Fortran. Currently, the library contains a generic, dynamically sizable list and a generic linked-list type.

Description

The collections library contains generic and dynamically sizeable collection types using unlimited polymorphic types with an object-oriented design.

Build

CMake is the preferred build system for this library. See Running CMake for instructions on how to build using CMake.

FPM can also be used to build this library using the provided fpm.toml.

fpm build

The COLLECTIONS library can be used within your FPM project by adding the following to your fpm.toml file.

[dependencies]
collections = { git = "https://github.com/jchristopherson/collections" }

Dependencies

This library depends upon the FERROR library.

Documentation

The documentation can be found here.

Examples

The collections library provides a generic, dynamically sizeable type referred to simply as list. A simple example illustrating basic usage of the list type is as follows.

program list_example
    use collections
    use iso_fortran_env
    implicit none

    ! Variables
    integer(int32), parameter :: n = 10
    integer(int32) :: i
    type(list) :: x
    class(*), pointer :: ptr

    ! Create a list
    do i = 1, n
        call x%push(2 * i)
    end do

    ! Print it out to the command line
    print '(A)', "***** Original List *****"
    do i = 1, n
        ptr => x%get(i)
        
        ! The list uses unlimited polymorphic types; therefore, we need to
        ! use the select type construct.
        select type (ptr)
        type is (integer(int32))
            print *, ptr
        end select
    end do

    ! Insert the integer value of 100 into the 5th slot in the list
    call x%insert(5, 100)

    ! Print it out again to illustrate the change
    print '(A)', new_line('a') // "***** After Insertion *****"
    do i = 1, x%count()
        ptr => x%get(i)
        select type (ptr)
        type is (integer(int32))
            print *, ptr
        end select
    end do
end program

This program generates the following output.

***** Original List *****
           2
           4
           6
           8
          10
          12
          14
          16
          18
          20

***** After Insertion *****
           2
           4
           6
           8
         100
          10
          12
          14
          16
          18
          20

The collections library also provides a generic linked-list type. A simple example illustrating basic usage of the linked-list type is as follows.

program linked_list_example
    use collections
    use iso_fortran_env
    implicit none

    ! Variables
    integer(int32), parameter :: n = 10
    integer(int32) :: i
    logical :: check
    type(linked_list) :: x
    class(*), pointer :: ptr

    ! Create a list
    do i = 1, n
        call x%push(i)
    end do

    ! Print it out
    print '(A)', "***** Original List *****"
    check = associated(x%get())
    do while (check)
        ptr => x%get()

        ! The list uses unlimited polymorphic types; therefore, we need to
        ! use the select type construct.
        select type (ptr)
        type is (integer(int32))
            print *, ptr
        end select

        ! Move to the next item
        check = x%next()
    end do

    ! Print out the item at the current iterator position
    print '(A)', new_line('a') // "***** Current Iterator Position *****"
    ptr => x%get()
    select type(ptr)
    type is (integer(int32))
        print *, ptr
    end select

    ! Move to the beginning of the collection
    print '(A)', new_line('a') // "***** Beginning *****"
    call x%move_to_first()
    ptr => x%get()
    select type (ptr)
    type is (integer(int32))
        print *, ptr
    end select
end program

This program generates the following output.

***** Original List *****
           1
           2
           3
           4
           5
           6
           7
           8
           9
          10

***** Current Iterator Position *****
          10

***** Beginning *****
           1

collections's People

Contributors

jchristopherson avatar

Stargazers

 avatar

Watchers

 avatar  avatar

collections's Issues

Dependency Build Scripts

The dependency portion of the build scripts currently work, but are in need of being cleaned up and redundant actions removed.

Documentation

Set up an action to create documentation on GH page.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.