-
Notifications
You must be signed in to change notification settings - Fork 102
Open
Labels
Description
unordered-containers/Data/HashMap/Internal.hs
Lines 2050 to 2054 in 10328f2
-- | /O(n)/ Construct a map with the supplied mappings. If the list | |
-- contains duplicate mappings, the later mappings take precedence. | |
fromList :: (Eq k, Hashable k) => [(k, v)] -> HashMap k v | |
fromList = L.foldl' (\ m (k, v) -> unsafeInsert k v m) empty | |
{-# INLINABLE fromList #-} |
By contrast, fromListWith
is documented to be O(n*log n).
The difference between these functions is that the former uses unsafeInsert
while the latter uses unsafeInsertWith
. Both are recursive though, so I don't understand how fromList
gets away with linear complexity?!