# How to implement custom EnumerableMap

**URL:** <https://forum.openzeppelin.com/t/how-to-implement-custom-enumerablemap/9653>\
**Category:** Contracts\
**Created:** [June 1, 2021, 4:55pm UTC](https://forum.openzeppelin.com/t/how-to-implement-custom-enumerablemap/9653 "2021-06-01T16:55:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gnarvaja](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/gnarvaja/32/21458_2.png) [@gnarvaja](https://forum.openzeppelin.com/u/gnarvaja)\
**Post date:** [June 1, 2021, 4:55pm UTC](https://forum.openzeppelin.com/t/how-to-implement-custom-enumerablemap/9653/1 "2021-06-01T16:55:37Z")

</div>

I’m trying to create a custom EnumerableMap, similar to UintToAddressMap (but in my case is → uint256). I created a new library and copied and adapted the code of UintToAddressMap, that uses Map as inner implementation. But it doesn’t works becase Map’s functions are defined as private.

How we are supposed to implement custom (not UintToAddress) maps?

If only Map is made public, it can be easily reimplemented just adding the adaptation functions.

---

<div class="post-metadata">

**Author:** ![Yoshiko](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/yoshiko/32/6858_2.png) [@Yoshiko](https://forum.openzeppelin.com/u/Yoshiko)\
**Post date:** [June 3, 2021, 6:33am UTC](https://forum.openzeppelin.com/t/how-to-implement-custom-enumerablemap/9653/2 "2021-06-03T06:33:18Z")

</div>

Hi gnarvaja welcome to Open Zeppelin!

Please post your code and we can take a look to see where the code is going wrong.

---

<div class="post-metadata">

**Author:** ![gnarvaja](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/gnarvaja/32/21458_2.png) [@gnarvaja](https://forum.openzeppelin.com/u/gnarvaja)\
**Post date:** [June 9, 2021, 7:46pm UTC](https://forum.openzeppelin.com/t/how-to-implement-custom-enumerablemap/9653/3 "2021-06-09T19:46:13Z")

</div>

Sorry the delay, I was busy.

For example I want to do a AddressToUintMap, implemented with the inner Map the same way EnumerableMap.UintToAddressMap does…

```auto
pragma solidity ^0.8.0;

import {EnumerableMap} from "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";

library DataTypes2 {

    // AddressToUintMap

    struct AddressToUintMap {
        EnumerableMap.Map _inner;
    }

    function _address_to_b32(address addr) internal pure returns (bytes32) {
      return bytes32(uint256(uint160(addr)));
    }

    function _b32_to_address(bytes32 b32) internal pure returns (address) {
      return address(uint160(uint256(b32)));
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(AddressToUintMap storage map, address key, uint256 value) internal returns (bool) {
        return EnumerableMap._set(map._inner, _address_to_b32(key), bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the key was removed from the map, that is if it was present.
     */
    function remove(AddressToUintMap storage map, address key) internal returns (bool) {
        return EnumerableMap._remove(map._inner, _address_to_b32(key));
    }

...

```

But when I try to compile I get this error:

```auto
TypeError: Member "_set" not found or not visible after argument-dependent lookup in type(library EnumerableMap).
  --> contracts/DataTypes-2.sol:31:16:
   |
31 | return EnumerableMap._set(map._inner, _address_to_b32(key), bytes32(value));
   | ^^^^^^^^^^^^^^^^^^

```

But if I edit manually EnumerableMap and change all `private` for `public`, then it compiles and allows me to have my custom enumerable maps without copying all the Map code.

Or perhaps there is another right way to produce custom EnumerableMaps…
