{"id":40245208,"url":"https://github.com/degawa/maps","last_synced_at":"2026-01-20T00:09:40.285Z","repository":{"id":155091983,"uuid":"631285593","full_name":"degawa/maps","owner":"degawa","description":"A practical wrapper for stdlib_hashmaps","archived":false,"fork":false,"pushed_at":"2023-11-14T02:02:28.000Z","size":101,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-23T12:56:36.668Z","etag":null,"topics":["fortran","fortran-package-manager","fortran-stdlib","hashmap","hashmaps","map","maps","modern-fortran"],"latest_commit_sha":null,"homepage":"","language":"Fortran","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/degawa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-04-22T14:36:56.000Z","updated_at":"2023-04-26T02:45:09.000Z","dependencies_parsed_at":"2023-11-22T20:37:36.292Z","dependency_job_id":"be0f407c-d767-49a6-b1a2-7220f83b8cf4","html_url":"https://github.com/degawa/maps","commit_stats":{"total_commits":88,"total_committers":1,"mean_commits":88.0,"dds":0.0,"last_synced_commit":"453d8b146a659c0111652fe0579e2321477c54cd"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/degawa/maps","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/degawa%2Fmaps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/degawa%2Fmaps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/degawa%2Fmaps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/degawa%2Fmaps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/degawa","download_url":"https://codeload.github.com/degawa/maps/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/degawa%2Fmaps/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28590676,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T00:01:37.455Z","status":"ssl_error","status_checked_at":"2026-01-19T23:58:17.328Z","response_time":67,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fortran","fortran-package-manager","fortran-stdlib","hashmap","hashmaps","map","maps","modern-fortran"],"created_at":"2026-01-20T00:09:39.681Z","updated_at":"2026-01-20T00:09:40.275Z","avatar_url":"https://github.com/degawa.png","language":"Fortran","funding_links":[],"categories":[],"sub_categories":[],"readme":"# maps\nA practical wrapper for stdlib_hashmaps\n\n## Motivation\nHashmaps are one of the most practical tools in versatile programming. Many versatile, relatively modern, and popular programming languages have hashmaps.\n\nFortran does not have hashmaps as the language standard, but hashmaps are being developed in the community-made standard library, [stdlib](https://github.com/fortran-lang/stdlib). However, the current implementation of the hashmaps requires some steps to perform the desired tasks: adding a key-value mapping and getting the value mapped to a key.\n\n```Fortran\ntype(chaining_hashmap_type) :: map\ncall map%init(fnv_1_hasher)\n\nblock\n    type(key_type) :: key\n    type(other_type) :: other\n    class(*), allocatable :: data\n\n    ! adding a key-value mapping to the map\n    call set(key, \"apple\")\n    call set(other, 100)\n    call map%map_entry(key, other)\n\n    ! getting the value mapped to a key\n    call set(key, \"apple\")\n    call map%get_other_data(key, other)\n    call get(other, data)\n    select type (data); type is (integer(int32))\n        print *, data, \"is mapped to apple\"\n    end select\nend block\n```\n\nThe wrapper provides a similar feel for operations to the hashmaps in other languages, hiding the abovementioned steps.\n\n```Fortran\nuse :: maps\ntype(char_to_int32_map_type) :: map\ncall map%initialize()\n\n! adding a key-value mapping to the map\ncall map%put(\"apple\", 100)\n\n! getting the value mapped to a key\nprint *, map%get(\"apple\")\n```\n\n## Getting started\n### Requirements\nSince maps use hashmaps in the stdlib, an environment that can build at least the stdlib is required. The compilers and versions listed below have been used to develop maps.\n\n- Modern Fortran compiler\n    - gfortran 11.2 bundled with [quickstart Fortran on Windows](https://github.com/LKedward/quickstart-fortran)\n    - Intel Fortran Classic 2021.5.0 Build 20211109_000000\n    - NAG Fortran 7.1 Build 7117\n- [Fortran-stdlib](https://github.com/fortran-lang/stdlib)\n- [Fortran Package Manager](https://github.com/fortran-lang/fpm) (fpm) 0.9.0 alpha\n\n### Get the code\nTo get the code, execute the following commnad:\n\n```console\ngit clone https://github.com/degawa/maps.git\ncd maps\n```\n\n### Build with fpm\nTo build the library using fpm, execute the following command:\n\n```console\nfpm build\n```\n\n### Reference from your project\nAdd the following `use` statement to modules or procedures that use maps.\n\n```Fortran\nuse :: maps\n```\n\n### Reference as a fpm project's dependency\nTo use maps in your fpm project, add the following to the fpm.toml.\n\n```TOML\n[dependencies]\nmaps = {git = \"https://github.com/degawa/maps.git\"}\n```\n\n## usage\nTo use a hashmap defined in maps, declare a hashmap instance and initialize it with the `initialize` procedure. When it is no longer needed, the `finalize` procedure destorys the instance.\n\nThe names of the hashmap types defined in maps follow the convention: `\u003ctype of key\u003e_to_\u003ctype of value\u003e_map_type`. For instance, the hashmap named `char_to_int32_map_type` maps keys of the `character(*)` type to `integer(int32)` type values.\n\n`any` means scalar values of the intrinsic types, including `integer(int8)`, `integer(int16)`, `integer(int32)`, `integer(int64)`, `real(real32)`, `real(real64)`, `real(real128)`, `complex(real32)`, `complex(real64)`, `complex(real128)`, `logical`, and `character(*)`. User-defined types are currently not supported.\n\n`char_to_any_map_type` can contain values of the intrinsic types. The value mapped to a key can be retrieved with the type-bound procedure `get`, regardless of its type. But conversion to the obtained type is required when putting it directly to a print or write statement, or passing it to a procedure:\n\n```Fortran\ntype(char_to_any_map_type) :: map\ncall map%initialize()\n\ncall map%put(\"int32.max\", huge(0_int32))\nblock\n    integer(int32) :: i32\n    i32 = map%get(\"int32.max\")\n    print *, i32, as_int32(map%get(\"int32.max\")) ! 2147483647  2147483647\nend block\n```\n\nThe conversion functions are listed below:\n- `as_int8()`\n- `as_int16()`\n- `as_int32()`\n- `as_int64()`\n- `as_real32()`\n- `as_real64()`\n- `as_real128()`\n- `as_complex32()`\n- `as_complex64()`\n- `as_complex128()`\n- `as_logical()`\n- `as_char()`\n\n### Basic examples\n#### char_to_int32_map\nThe `char_to_int32_map_type` maps keys of the `character(*)` type to `integer(int32)` type values.\n\n```Fortran\nuse :: maps\nimplicit none\n\ntype(char_to_int32_map_type) :: map\ncall map%initialize()\n\ncall map%put(\"apple\", 100)\ncall map%put(\"orange\", 150)\ncall map%put(\"banana\", 200)\n\nprint *, map%get(\"banana\") ! 200\n\nprint *, map%contains(\"orange\") ! T\ncall map%remove_if(\"orange\", 100)\nprint *, map%contains(\"orange\") ! T\ncall map%remove_if(\"orange\", 150)\nprint *, map%contains(\"orange\") ! F\n```\n\n#### char_to_any_map\nThe `char_to_any_map_type` maps keys of the `character(*)` type to values of the intrinsic types.\n\n```Fortran\nuse, intrinsic :: iso_fortran_env\nuse :: maps\nimplicit none\n\ntype(char_to_any_map_type) :: map\ncall map%initialize()\n\ncall map%put(\"int8.max\", huge(0_int8))\ncall map%put(\"int16.max\", huge(0_int16))\ncall map%put(\"int32.max\", huge(0_int32))\ncall map%put(\"int64.max\", huge(0_int64))\ncall map%put(\"real32.max\", huge(0._real32))\ncall map%put(\"real64.max\", huge(0._real64))\n\nprint *, as_int32(map%get(\"int32.max\")) ! 2147483647\nprint *, as_real64(map%get(\"real64.max\")) ! 1.7976931348623157E+308\n\nblock\n    integer(int8) :: i8\n    real(real32) :: r32\n    i8 = map%get(\"int8.max\")\n    r32 = map%get(\"real32.max\")\n    print *, i8, r32 ! 127   3.40282347E+38\nend block\n\ncall map%remove_if(\"real64.max\", huge(0._real64))\nprint *, map%contains(\"real64.max\") ! F\n```\n\n#### any_to_int32_map\nThe `any_to_int32_map_type` maps keys of the intrinsic types to `integer(int32)` type values. This type is provided only for demonstrating the feasibility of the hashmaps in stdlib and may not be suitable for practical use.\n\n```Fortran\nuse :: maps\nimplicit none\n\ntype(any_to_int32_map_type) :: map\ncall map%initialize()\n\ncall map%put(100, 200)\nprint *, map%get(100) ! 200\n```\n\n#### bitset_to_int32_map\nThe `bitset_to_int32_map_type` maps keys of the bitset types, `bitset_64` and `bitset_large`, to `integer(int32)` type values.\n\n```Fortran\nuse :: maps\nimplicit none\n\ntype(bitset_to_int32_map_type) :: map\ntype(bitset_large) :: key\ninteger(int32) :: cell_id\n\ncall map%initialize()\n\ncall key%from_string(\"11100011\")\ncell_id = 3\ncall map%put(key, cell_id)\n\nprint *, map%get(key) ! 3\n```\n\n#### note\nIf the error `build\\dependencies\\stdlib\\src\\stdlib_hashmap_wrappers.f90, line 290: allocatable KEY%VALUE is not allocated` occurs when using NAG Fortran compiler, modify line 290-291 on `stdlib_hashmap_wrappers.f90` as follows:\n```diff\n-        key % value = transfer( value, key % value, \u0026\n-                                bytes_char * len( value ) )\n+        key % value = transfer( value, int(0, kind=kind(key%value)), \u0026\n+                                bytes_char * len( value ) )\n```\n\n## Todo\n- [ ] To add unit tests.\n- [ ] To support user-defined types.\n- [x] To add finializer.\n- [ ] To add some procedures.\n- [x] To add some hashmaps.\n- [x] To define status code.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdegawa%2Fmaps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdegawa%2Fmaps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdegawa%2Fmaps/lists"}