@@ -40,6 +40,7 @@ import {EnumerableSet} from "./EnumerableSet.sol";
4040 * - `address -> bytes32` (`AddressToBytes32Map`) since v5.1.0
4141 * - `bytes32 -> address` (`Bytes32ToAddressMap`) since v5.1.0
4242 * - `bytes -> bytes` (`BytesToBytesMap`) since v5.4.0
43+ * - `bytes4 -> address` (`Bytes4ToAddressMap`) since v5.6.0
4344 *
4445 * [WARNING]
4546 * ====
@@ -1187,6 +1188,129 @@ library EnumerableMap {
11871188 return result;
11881189 }
11891190
1191+ // Bytes4ToAddressMap
1192+
1193+ struct Bytes4ToAddressMap {
1194+ Bytes32ToBytes32Map _inner;
1195+ }
1196+
1197+ /**
1198+ * @dev Adds a key-value pair to a map, or updates the value for an existing
1199+ * key. O(1).
1200+ *
1201+ * Returns true if the key was added to the map, that is if it was not
1202+ * already present.
1203+ */
1204+ function set (Bytes4ToAddressMap storage map , bytes4 key , address value ) internal returns (bool ) {
1205+ return set (map._inner, bytes32 (key), bytes32 (uint256 (uint160 (value))));
1206+ }
1207+
1208+ /**
1209+ * @dev Removes a value from a map. O(1).
1210+ *
1211+ * Returns true if the key was removed from the map, that is if it was present.
1212+ */
1213+ function remove (Bytes4ToAddressMap storage map , bytes4 key ) internal returns (bool ) {
1214+ return remove (map._inner, bytes32 (key));
1215+ }
1216+
1217+ /**
1218+ * @dev Removes all the entries from a map. O(n).
1219+ *
1220+ * WARNING: This function has an unbounded cost that scales with map size. Developers should keep in mind that
1221+ * using it may render the function uncallable if the map grows to the point where clearing it consumes too much
1222+ * gas to fit in a block.
1223+ */
1224+ function clear (Bytes4ToAddressMap storage map ) internal {
1225+ clear (map._inner);
1226+ }
1227+
1228+ /**
1229+ * @dev Returns true if the key is in the map. O(1).
1230+ */
1231+ function contains (Bytes4ToAddressMap storage map , bytes4 key ) internal view returns (bool ) {
1232+ return contains (map._inner, bytes32 (key));
1233+ }
1234+
1235+ /**
1236+ * @dev Returns the number of elements in the map. O(1).
1237+ */
1238+ function length (Bytes4ToAddressMap storage map ) internal view returns (uint256 ) {
1239+ return length (map._inner);
1240+ }
1241+
1242+ /**
1243+ * @dev Returns the element stored at position `index` in the map. O(1).
1244+ * Note that there are no guarantees on the ordering of values inside the
1245+ * array, and it may change when more values are added or removed.
1246+ *
1247+ * Requirements:
1248+ *
1249+ * - `index` must be strictly less than {length}.
1250+ */
1251+ function at (Bytes4ToAddressMap storage map , uint256 index ) internal view returns (bytes4 key , address value ) {
1252+ (bytes32 atKey , bytes32 val ) = at (map._inner, index);
1253+ return (bytes4 (atKey), address (uint160 (uint256 (val))));
1254+ }
1255+
1256+ /**
1257+ * @dev Tries to return the value associated with `key`. O(1).
1258+ * Does not revert if `key` is not in the map.
1259+ */
1260+ function tryGet (Bytes4ToAddressMap storage map , bytes4 key ) internal view returns (bool exists , address value ) {
1261+ (bool success , bytes32 val ) = tryGet (map._inner, bytes32 (key));
1262+ return (success, address (uint160 (uint256 (val))));
1263+ }
1264+
1265+ /**
1266+ * @dev Returns the value associated with `key`. O(1).
1267+ *
1268+ * Requirements:
1269+ *
1270+ * - `key` must be in the map.
1271+ */
1272+ function get (Bytes4ToAddressMap storage map , bytes4 key ) internal view returns (address ) {
1273+ return address (uint160 (uint256 (get (map._inner, bytes32 (key)))));
1274+ }
1275+
1276+ /**
1277+ * @dev Returns an array containing all the keys
1278+ *
1279+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
1280+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
1281+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
1282+ * uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
1283+ */
1284+ function keys (Bytes4ToAddressMap storage map ) internal view returns (bytes4 [] memory ) {
1285+ bytes32 [] memory store = keys (map._inner);
1286+ bytes4 [] memory result;
1287+
1288+ assembly ("memory-safe" ) {
1289+ result := store
1290+ }
1291+
1292+ return result;
1293+ }
1294+
1295+ /**
1296+ * @dev Returns an array containing a slice of the keys
1297+ *
1298+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
1299+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
1300+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
1301+ * uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
1302+ */
1303+ function keys (Bytes4ToAddressMap storage map , uint256 start , uint256 end ) internal view returns (bytes4 [] memory ) {
1304+ bytes32 [] memory store = keys (map._inner, start, end);
1305+ bytes4 [] memory result;
1306+
1307+ assembly ("memory-safe" ) {
1308+ result := store
1309+ }
1310+
1311+ return result;
1312+ }
1313+
11901314 /**
11911315 * @dev Query for a nonexistent map key.
11921316 */
0 commit comments