@@ -1534,12 +1534,38 @@ fromList :: (Eq k, Hashable k) => [(k, v)] -> HashMap k v
1534
1534
fromList = L. foldl' (\ m (k, v) -> unsafeInsert k v m) empty
1535
1535
{-# INLINABLE fromList #-}
1536
1536
1537
+ -- | /O(n)/ Construct a map with the supplied mappings. If the list
1538
+ -- contains duplicate mappings, the later mappings take precedence.
1539
+ -- Returns a tuple with the size of the created hashmap and the hashmap
1540
+ -- itself.
1541
+ fromListInternal :: (Eq k , Hashable k ) => [(k , v )] -> (Int , HashMap k v )
1542
+ fromListInternal = L. foldl' (\ (sz, m) (k, v) ->
1543
+ let (s, m') = unsafeInsertInternal k v m
1544
+ in (sz + s, m'))
1545
+ (0 , empty)
1546
+ {-# INLINABLE fromListInternal #-}
1547
+
1537
1548
-- | /O(n*log n)/ Construct a map from a list of elements. Uses
1538
1549
-- the provided function to merge duplicate entries.
1539
1550
fromListWith :: (Eq k , Hashable k ) => (v -> v -> v ) -> [(k , v )] -> HashMap k v
1540
1551
fromListWith f = L. foldl' (\ m (k, v) -> unsafeInsertWith f k v m) empty
1541
1552
{-# INLINE fromListWith #-}
1542
1553
1554
+ -- | /O(n*log n)/ Construct a map from a list of elements. Uses
1555
+ -- the provided function to merge duplicate entries.
1556
+ -- Returns a tuple with the size of the created hashmap and the hashmap itself.
1557
+ fromListWithInternal
1558
+ :: (Eq k , Hashable k )
1559
+ => (v -> v -> v )
1560
+ -> [(k , v )]
1561
+ -> (Int , HashMap k v )
1562
+ fromListWithInternal f =
1563
+ L. foldl' (\ (sz, m) (k, v) ->
1564
+ let (s, m') = unsafeInsertWithInternal f k v m
1565
+ in (sz + s, m'))
1566
+ (0 , empty)
1567
+ {-# INLINE fromListWithInternal #-}
1568
+
1543
1569
------------------------------------------------------------------------
1544
1570
-- Array operations
1545
1571
0 commit comments