-
Notifications
You must be signed in to change notification settings - Fork 192
Open
Labels
topic: container(Abstract) data structures and containers(Abstract) data structures and containerstopic: utilitiescontainers, strings, files, OS/environment integration, unit testing, assertions, logging, ...containers, strings, files, OS/environment integration, unit testing, assertions, logging, ...
Description
Problem
Linked list is one of the essential data structures beside an array. It allows you to add, insert, or remove elements in constant time, without re-allocating the whole structure.
Fortran doesn't have a linked list. There are 3rd party libraries, but no obvious go-to solution. Fortran stdlib should have a linked list. I would use it.
Examples
- FLIBS by @arjenmarkus
- fortran-list by @LadaF
- flist by @jacobwilliams
- PolyCon by @cmacmackin
- Petaca by @nncarlson
- Modern Fortran Explained by MRC has an implementation in Appendix C
- Many others?
What kind of data can the linked list hold?
There's various levels of capability we could pursue:
- Single type: Basically just like an array, but allows insertion in constant time;
- Elements can be of any intrinsic type in a single list;
- Can take intrinsic type and user-defined derived types (is this even possible in current Fortran?)
API
I don't know, something like this?
use stdlib_experimental_collections, only :: List
type(List) :: a = List()
call a % append(42)
call a % append(3.141)
call a % append('text')
print *, a % get(2) ! prints 3.141
call a % remove(3) ! a is now List([42, 3.141])
call a % insert(2, 'hello') ! a is now List([42, 'hello', 3.141])
a = List([1, 2, 3]) ! instantiate a list from an array
ngs333
Metadata
Metadata
Assignees
Labels
topic: container(Abstract) data structures and containers(Abstract) data structures and containerstopic: utilitiescontainers, strings, files, OS/environment integration, unit testing, assertions, logging, ...containers, strings, files, OS/environment integration, unit testing, assertions, logging, ...