Skip to content
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

Adding a procedure getting all keys in the hashmaps #732

Closed
degawa opened this issue Aug 20, 2023 · 2 comments · Fixed by #741
Closed

Adding a procedure getting all keys in the hashmaps #732

degawa opened this issue Aug 20, 2023 · 2 comments · Fixed by #741
Labels
idea Proposition of an idea and opening an issue to discuss it

Comments

@degawa
Copy link
Contributor

degawa commented Aug 20, 2023

Motivation

The hashmap in the stdlib does not provide a way to retrieve all keys in the map. As shown in the Prior Art section, a way to retrieve all keys in a hashmap is required in other programming languages, and it would significantly expands the use of the hashmap.

Prior Art

The Map in Java has the SetKey() method that returns the keys in this map.
The list() function for Python's dict returns a list of all the keys used in the dictionary.
The unordered_map in C++ does not have a similar method, but a way to get all the keys is required. (for example, see https://stackoverflow.com/questions/8483985/obtaining-list-of-keys-and-values-from-unordered-map)

Additional Information

The hashmaps in the stdlib, including open_hash_map_type and chaining_hash_map_type, store both the entered keys and values to the component inverse. So it is not challenging work to retrieve the keys as a key_type array.
The conversion from the key_type to the original type is left to the users.

@degawa degawa added the idea Proposition of an idea and opening an issue to discuss it label Aug 20, 2023
@awvwgk
Copy link
Member

awvwgk commented Aug 20, 2023

In TOML Fortran the map types support returning a list of keys, which can be used to iterate through the data structure. In general using stdlib' s map type in TOML Fortran requires this functionality, and one way of implementing this would be to just store the keys in a list beside the map.

@jvdp1
Copy link
Member

jvdp1 commented Sep 4, 2023

Thank you @degawa for the proposal.

The hashmaps in the stdlib, including open_hash_map_type and chaining_hash_map_type, store both the entered keys and values to the component inverse. So it is not challenging work to retrieve the keys as a key_type array.

It seems you already have an idea on how to implement such an option. Would you like to open a PR for its implemenation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea Proposition of an idea and opening an issue to discuss it
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants