Skip to content

pop, drop & get with basic range feature for stringlist #514

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

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
933a367
resolved inserting 0 lengthed slist in list bug
aman-godara Oct 10, 2021
ea46f19
changed name
aman-godara Oct 10, 2021
c790494
added delete function for stringlist
aman-godara Sep 6, 2021
e446e7a
completed TODO by adding move subroutine
aman-godara Sep 6, 2021
bfad13d
renamed delete to pop, created subroutine drop
aman-godara Sep 12, 2021
00de2b7
fixed an error in documentation of stringlist
aman-godara Sep 12, 2021
92d5f0d
created a new subroutine pop_positions
aman-godara Sep 12, 2021
1468fb6
added range functions for pop and drop
aman-godara Sep 12, 2021
937fac2
corrected a typo
aman-godara Sep 12, 2021
f60dd9e
corrected errors in documentation
aman-godara Sep 13, 2021
88a1abb
added range feature for get, added shift function
aman-godara Sep 13, 2021
ccd6dff
made move subroutine of stdlib_string_type module pure
aman-godara Sep 13, 2021
2e216c8
some minor changes
aman-godara Sep 15, 2021
5d24c0c
rename capture_popped to popped_strings
aman-godara Sep 17, 2021
48c94dc
renamed to popped_strings all over the function
aman-godara Sep 17, 2021
980c18a
removing redundant naming convention
aman-godara Sep 26, 2021
e935ea1
improved append operator's performance
aman-godara Sep 26, 2021
e34cce2
changed naming convention throughout the module
aman-godara Sep 26, 2021
2b3a5ef
some minor improvements
aman-godara Oct 15, 2021
29f9880
Minor refactoring
aman-godara Dec 25, 2021
207c1fb
Add strides feature to get function
aman-godara Dec 26, 2021
e6b6143
Add get_impl interface in the middle
aman-godara Dec 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Minor refactoring
  • Loading branch information
aman-godara committed Dec 25, 2021
commit 29f988024b88fd658eba2080ac0b9026a21fec66
64 changes: 36 additions & 28 deletions src/stdlib_stringlist_type.f90
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,16 @@ end function new_stringlist

!> Constructor to convert chararray to stringlist
!> Returns a new instance of type stringlist
pure function new_stringlist_carray( array )
character(len=*), dimension(:), intent(in) :: array
pure function new_stringlist_carray( carray )
character(len=*), dimension(:), intent(in) :: carray
type(stringlist_type) :: new_stringlist_carray

type(string_type), allocatable :: sarray(:)
type(string_type), dimension(:), allocatable :: sarray
integer :: i

allocate( sarray( size(array) ) )
do i = 1, size(array)
sarray(i) = string_type( array(i) )
allocate( sarray( size(carray) ) )
do i = 1, size(carray)
sarray(i) = string_type( carray(i) )
end do

call move_alloc( sarray, new_stringlist_carray%stringarray )
Expand All @@ -186,31 +186,31 @@ end function new_stringlist_carray

!> Constructor to convert stringarray to stringlist
!> Returns a new instance of type stringlist
pure function new_stringlist_sarray( array )
type(string_type), dimension(:), intent(in) :: array
pure function new_stringlist_sarray( sarray )
type(string_type), dimension(:), intent(in) :: sarray
type(stringlist_type) :: new_stringlist_sarray

new_stringlist_sarray%stringarray = array
new_stringlist_sarray%stringarray = sarray

end function new_stringlist_sarray

! constructor for stringlist_index_type:

!> Returns an instance of type 'stringlist_index_type' representing forward index 'idx'
pure function forward_index( idx )
integer, intent(in) :: idx
!> Returns an instance of type 'stringlist_index_type' representing forward index 'idxn'
pure function forward_index( idxn )
integer, intent(in) :: idxn
type(stringlist_index_type) :: forward_index

forward_index = stringlist_index_type( .true., idx )
forward_index = stringlist_index_type( .true., idxn )

end function forward_index

!> Returns an instance of type 'stringlist_index_type' representing backward index 'idx'
pure function backward_index( idx )
integer, intent(in) :: idx
!> Returns an instance of type 'stringlist_index_type' representing backward index 'idxn'
pure function backward_index( idxn )
integer, intent(in) :: idxn
type(stringlist_index_type) :: backward_index

backward_index = stringlist_index_type( .false., idx )
backward_index = stringlist_index_type( .false., idxn )

end function backward_index

Expand Down Expand Up @@ -695,9 +695,10 @@ pure subroutine insert_before_chararray_idxn( list, idxn, carray )
work_idxn = idxn
call insert_before_engine( list, work_idxn, size( carray ) )

inew = work_idxn
do i = 1, size( carray )
inew = work_idxn + i - 1
list%stringarray(inew) = string_type( carray(i) )
inew = inew + 1
end do

end subroutine insert_before_chararray_idxn
Expand All @@ -718,9 +719,10 @@ pure subroutine insert_before_stringarray_idxn( list, idxn, sarray )
work_idxn = idxn
call insert_before_engine( list, work_idxn, size( sarray ) )

inew = work_idxn
do i = 1, size( sarray )
inew = work_idxn + i - 1
list%stringarray(inew) = sarray(i)
inew = inew + 1
end do

end subroutine insert_before_stringarray_idxn
Expand All @@ -729,19 +731,19 @@ end subroutine insert_before_stringarray_idxn

!> Version: experimental
!>
!> Returns strings present at stringlist_indexes in interval ['first', 'last']
!> Returns strings present at integer indexes in interval ['firstn', 'lastn']
!> Stores requested strings in array 'capture_strings'
!> No return
pure subroutine get_engine( list, first, last, capture_strings )
pure subroutine get_engine( list, firstn, lastn, capture_strings )
type(stringlist_type), intent(in) :: list
type(stringlist_index_type), intent(in) :: first, last
integer, intent(in) :: firstn, lastn
type(string_type), allocatable, intent(out) :: capture_strings(:)

integer :: from, to
integer :: i, inew

from = max( list%to_current_idxn( first ), 1 )
to = min( list%to_current_idxn( last ), list%len() )
from = max( firstn, 1 )
to = min( lastn, list%len() )

! out of bounds indexes won't be captured in 'capture_strings'
if ( from <= to ) then
Expand All @@ -766,11 +768,13 @@ end subroutine get_engine
pure function get_idx( list, idx )
class(stringlist_type), intent(in) :: list
type(stringlist_index_type), intent(in) :: idx

type(string_type) :: get_idx

integer :: idxn
type(string_type), allocatable :: capture_strings(:)

call get_engine( list, idx, idx, capture_strings )
idxn = list%to_current_idxn( idx )
call get_engine( list, idxn, idxn, capture_strings )

! if index 'idx' is out of bounds, returns an empty string
if ( size(capture_strings) == 1 ) then
Expand All @@ -786,10 +790,14 @@ end function get_idx
pure function get_range_idx( list, first, last )
class(stringlist_type), intent(in) :: list
type(stringlist_index_type), intent(in) :: first, last

type(string_type), allocatable :: get_range_idx(:)

call get_engine( list, first, last, get_range_idx )
integer :: firstn, lastn

firstn = list%to_current_idxn( first )
lastn = list%to_current_idxn( last )

call get_engine( list, firstn, lastn, get_range_idx )

end function get_range_idx

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy