Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Sorting string's characters according to their ASCII values #363

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

Open
ChetanKarwa wants to merge 1 commit into fortran-lang:master
base: master
Choose a base branch
Loading
from ChetanKarwa:master
Open

Conversation

Copy link
Member

@ChetanKarwa ChetanKarwa commented Mar 26, 2021
edited
Loading

I have implemented a sort function for a string. This function sorts the string's characters according to their ASCII values.

Eg:
string - "This is to be sorted"
sorted string - " Tbdeehiioorssstt"

Copy link
Member

ivan-pi commented Mar 26, 2021

Hello @ChetanKarwa,

great to see you managed to build stdlib and get your new function working.

However, I am not totally convinced by the purpose of this function. The more common usage of a sort function would be to sort a list of strings (like the one in development in #311), say to output a sorted list of labels.

Do you have some usage cases that motivate a character sort function?

awvwgk reacted with thumbs up emoji

Copy link
Member Author

I implemented this because I've seen other languages supporting the sorting of a character array.
But they support a general sort function they don't have a separate sort function for the character array and that function is slow [time complexity - O(N*logN)]. So I thought of implementing something different for Fortran stdlib and so the one implemented in this PR is O(N).
Now giving a second thought to it currently I really can't figure out any use case of this function.

@awvwgk awvwgk added topic: utilities containers, strings, files, OS/environment integration, unit testing, assertions, logging, ... idea Proposition of an idea and opening an issue to discuss it reviewers needed This patch requires extra eyes labels Apr 17, 2021
Copy link
Member

jvdp1 commented Apr 21, 2021

@wclodius2 Is your implementation related to this PR?

Copy link
Contributor

No, it isn't. My sort is of an array of elements of the string_type and not of the characters of a string_type scalar, or of a list of elements of the string_type. FWIW I also view sorting of the characters as of very limited use, and sorting a list rather than an array would require aa drastic rewrite of my code.

jvdp1 and ivan-pi reacted with thumbs up emoji

@jvdp1 jvdp1 changed the title (削除) Added sort to stdlib_string_type.f90 file (削除ここまで) (追記) Sorting string's characters according to their ASCII values (追記ここまで) May 24, 2021
Copy link
Member

jvdp1 commented May 24, 2021

I renamed this PR to avoid confusion with #408

ChetanKarwa reacted with thumbs up emoji

Copy link
Member

ivan-pi commented May 24, 2021

What could be done is to provide the O(n) sorting algorithm of @ChetanKarwa as a specialization in #408 when the input is an array of character(len=1), but I don't expect this to be used very often.

The only usage I can think of currently is to find the median letter (and maybe the mode) in a character sequence.

14NGiestas reacted with thumbs up emoji

Copy link
Member

awvwgk commented May 24, 2021

Also, consider that this implementation is likely to fail for non-ASCII input:

print *, sort("Ångström")
! Fortran runtime error: Index '195' of dimension 1 of array 'count' above upper bound of 128

@awvwgk awvwgk added waiting for OP This patch requires action from the OP and removed reviewers needed This patch requires extra eyes labels Jul 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
idea Proposition of an idea and opening an issue to discuss it topic: utilities containers, strings, files, OS/environment integration, unit testing, assertions, logging, ... waiting for OP This patch requires action from the OP
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /