containers
Assorted concrete container types
Version on this page: | 0.5.11.0 |
LTS Haskell 23.0: | 0.6.8 |
Stackage Nightly 2024-12-09: | 0.6.8 |
Latest on Hackage: | 0.7 |
containers-0.5.11.0@sha256:9f2e213dd95477ff35a3909df4e3cabaf46b7cc0c9b9082a92c0493db172fa25,16671
Module documentation for 0.5.11.0
- Data
- Data.Graph
- Data.IntMap
- Data.IntSet
- Data.Map
- Data.Map.Internal
- Data.Map.Lazy
- Data.Map.Lazy.Merge
- Data.Map.Merge
- Data.Map.Strict
- Data.Map.Strict.Internal
- Data.Map.Strict.Merge
- Data.Sequence
- Data.Set
- Data.Tree
- Utils
- Utils.Containers
- Utils.Containers.Internal
- Utils.Containers
This package contains efficient general-purpose implementations of various immutable container types including sets, maps, sequences, trees, and graphs.
For a walkthrough of what this package provides with examples of common operations see the containers introduction.
The declared cost of each operation is either worst-case or amortized, but remains valid even if structures are shared.
Changes
Changelog for containers
package
0.5.11
- Released with GHC 8.4.
New functions and class instances
-
Add a
MonadFix
instance forData.Sequence
. -
Add a
MonadFix
instance forData.Tree
. -
Add
powerSet
,cartesianProduct
, anddisjointUnion
forData.Set
. (Thanks, Edward Kmett.) -
Add
disjoint
forData.Set
andData.IntSet
. (Thanks, Víctor López Juan.) -
Add
lookupMin
andlookupMax
toData.IntMap
. (Thanks, bwroga.) -
Add
unzip
andunzipWith
toData.Sequence
. Make unzipping build its results in lockstep to avoid certain space leaks. -
Add carefully optimized implementations of
sortOn
andunstableSortOn
toData.Sequence
. (Thanks, Donnacha Oisín Kidney.)
Changes to existing functions and features
-
Make
Data.Sequence.replicateM
a synonym forreplicateA
for post-AMPbase
. -
Rewrite the
IsString
instance head for sequences, improving compatibility with the list instance and also improving type inference. We used to haveinstance IsString (Seq Char)
Now we commit more eagerly with
instance a ~ Char => IsString (Seq a)
-
Make
>>=
forData.Tree
strict in the result of its second argument; being too lazy here is almost useless, and violates one of the monad identity laws. Specifically,return () >>= \_ -> undefined
should always beundefined
, but this was not the case. -
Harmonize laziness details for
minView
andmaxView
betweenData.IntMap
andData.Map
.
Performance improvement
- Speed up both stable and unstable sorting for
Data.Sequence
by (Thanks, Donnacha Oisín Kidney.)
Other changes
-
Update for recent and upcoming GHC and Cabal versions (Thanks, Herbert Valerio Reidel, Simon Jakobi, and Ryan Scott.)
-
Improve external and internal documentation (Thanks, Oleg Grenrus and Benjamin Hodgson.)
-
Add tutorial-style documentation.
-
Add Haddock
@since
annotations for changes made since version 0.5.4 (Thanks, Simon Jakobi.) -
Add a (very incomplete) test suite for
Data.Tree
. -
Add structural validity checks to the test suites for
Data.IntMap
andData.IntSet
(Thanks to Joachim Breitner for catching an error in a first draft.)
0.5.10.2
-
Released with GHC 8.2.
-
Use
COMPLETE
pragmas to declare complete sets of pattern synonyms forData.Sequence
. At last! -
Make
Data.IntMap.Strict.traverseWithKey
force the values before installing them in the result. Previously, this function could be used to produce anIntMap
containing undefined values. -
Fix strictness bugs in various rewrite rules for
Data.Map.Strict
andData.IntMap.Strict
. Previously, rules could unintentionally reduce strictness. The most important change in this regard is the elimination of rules rewriting*.Strict.map coerce
tocoerce
. To map a coercion over a structure for free, be sure to use the lazymap
orfmap
. It is possible to write rules that do a somewhat better job of this, but it turns out to be a bit messy. -
Optimize
Data.IntMap.restrictKeys
andData.IntMap.withoutKeys
. The semantic fix in 0.5.10.1 left them rather slow in certain cases. -
Speed up
size
forIntSet
andIntMap
(thanks, Mike Ledger!). -
Define a custom
liftA2
inApplicative
instances for base 4.10, and useliftA2
rather than<*>
whenever it may be beneficial. -
Add
liftA2
-relatedRULES
forData.Sequence
. -
Export non-deprecated versions of
showTree
andshowTreeWith
fromData.IntMap.Internal.Debug
.
0.5.10.1
-
Fix completely incorrect implementations of
Data.IntMap.restrictKeys
andData.IntMap.withoutKeys
. Make the tests for these actually run. (Thanks to Tom Smalley for reporting this.) -
Fix a minor bug in the
Show1
instance ofData.Tree
. This produced valid output, but with fewer parentheses thanShow
. (Thanks, Ryan Scott.) -
Add
MonadZip
instance forData.Sequence
. -
Remove meaningless stability annotations (Thanks, Simon Jakobi.)
0.5.9.2
- Backport bug fixes from 0.5.10.1
0.5.9.1
-
Add
merge
andmergeA
forData.IntMap
. -
Add instances for
Data.Graph.SCC
:Foldable
,Traversable
,Data
,Generic
,Generic1
,Eq
,Eq1
,Show
,Show1
,Read
, andRead1
. -
Add lifted instances (from
Data.Functor.Classes
) forData.Sequence
,Data.Map
,Data.Set
,Data.IntMap
, andData.Tree
. (Thanks to Oleg Grenrus for doing a lot of this work.) -
Properly deprecate functions in
Data.IntMap
long documented as deprecated. -
Rename several internal modules for clarity. Thanks to esoeylemez for starting this process.
-
Make
Data.Map.fromDistinctAscList
andData.Map.fromDistinctDescList
more eager, improving performance. -
Plug space leaks in
Data.Map.Lazy.fromAscList
andData.Map.Lazy.fromDescList
by manually inlining constant functions. -
Add
lookupMin
andlookupMax
toData.Set
andData.Map
as total alternatives tofindMin
andfindMax
. -
Add
!?
toData.Map
as a total alternative to!
. -
Avoid using
deleteFindMin
anddeleteFindMax
internally, preferring total functions instead. New implementations of said functions lead to slight performance improvements overall.
0.5.8.2
- Backport bug fixes from 0.5.10.1.
0.5.8.1 Aug 2016
General package changes
-
Remove all attempts to support nhc98 and any versions of GHC before 7.0.
-
Integrate benchmarks with Cabal. (Thanks, Gabriel Gonzalez!)
-
Make Cabal report required extensions properly, and stop using default extensions. Note that we do not report extensions conditionally enabled based on GHC version, as doing so would lead to a maintenance nightmare with no obvious benefits.
-
Use
BangPatterns
throughout to reduce noise. This extension is now required to compilecontainers
. -
Improve QuickCheck properties taking arbitrary functions by using
Test.QuickCheck.Function.Fun
instead of evilShow
instances for functions. -
Expose several internal modules through Cabal (as requested by Edward Kmett). These remain completely unsupported.
New exports and instances
-
Add
alterF
,restrictKeys
, andwithoutKeys
toData.Map
andData.IntMap
. -
Add
take
,drop
,splitAt
,takeWhileAntitone
,dropWhileAntitone
, andspanAntitone
forData.Map
andData.Set
. Thanks to Cale Gibbard for suggesting these. -
Add
merge
,mergeA
, and associated merge tactics forData.Map
. Many thanks to Cale Gibbard, Ryan Trinkle, and Dan Doel for inspiring the merge idea and helping refine the interface. -
Add
traverseMaybeWithKey
,fromDescList
,fromDescListWith
,fromDescListWithKey
, andfromDistinctDescList
toData.Map
. -
Add
fromDescList
andfromDistinctDescList
toData.Set
. -
Add
Empty
,:<|
, and:|>
pattern synonyms forData.Sequence
. -
Add
adjust'
,(!?)
,lookup
,chunksOf
,cycleTaking
,insertAt
,deleteAt
,intersperse
,foldMapWithIndex
, andtraverseWithIndex
forData.Sequence
. -
Derive
Generic
andGeneric1
forData.Tree.Tree
,Data.Sequence.ViewL
, andData.Sequence.ViewR
. -
Add
foldTree
forData.Tree
. (Thanks, Daniel Wagner!)
Semantic changes
-
Make
Data.Sequence.splitAt
strict in its arguments. Previously, it returned a lazy pair. -
Fix completely erroneous definition of
length
forData.Sequence.ViewR
. -
Make
Data.Map.Strict.traverseWithKey
force result values before installing them in the new map. -
Make
drawTree
handle newlines better. (Thanks, recursion-ninja!)
Deprecations
-
All functions in
Data.Map
proper that have been documented as deprecated since version 0.5 or before now haveDEPRECATED
pragmas and will actually be removed after another cycle or two. -
Tree printing functions in
Data.Map
intended for library debugging are now deprecated. They will continue to be available for the foreseeable future in an internal module.
Performance changes
-
Substantially speed up
splitAt
,zipWith
,take
,drop
,fromList
,partition
,foldl'
, andfoldr'
forData.Sequence
. Special thanks to Lennart Spitzner for digging into the performance problems with previous versions offromList
and finding a way to make it really fast. Slightly optimizereplicateA
. Stoptraverse
from performing many unnecessaryfmap
operations. -
Most operations in
Data.Sequence
advertised as taking logarithmic time (including><
andadjust
) now use their full allotted time to avoid potentially building up chains of thunks in the tree. In general, the only remaining operations that avoid doing more than they really need are the particular bulk creation and transformation functions that really benefit from the extra laziness. There are some situations where this change may slow programs down, but I think having more predictable and usually better performance more than makes up for that. -
Add rewrite rules to fuse
fmap
withreverse
forData.Sequence
. -
Switch from hedge algorithms to divide-and-conquer algorithms for union, intersection, difference, and merge in both
Data.Map
andData.Set
. These algorithms are simpler, are known to be asymptotically optimal, and are faster according to our benchmarks. -
Speed up
adjust
forData.Map
. Allowmap
to inline, and define a custom(<$)
. This considerably improves mapping with a constant function. -
Remove non-essential laziness in
Data.Map.Lazy
implementation. -
Speed up deletion and alteration functions for
Data.IntMap
.
0.5.7.1 Dec 2015
-
Planned to bundle with GHC 8.0.1.
-
Add
IsString
instance toData.Sequence
. -
Define
Semigroup
instances forData.Map
,Data.Set
,Data.IntMap
,Data.IntSet
andData.Sequence
.
0.5.6.2 Dec 2014
-
Bundled with GHC 7.10.1.
-
Add role annotations for
Data.Map
andData.Set
. -
Add
IsList
instances forData.Map
,Data.Set
,Data.IntMap
andData.IntSet
. -
Several performance improvements for
Data.Sequence
. -
Add
Data.Sequence.fromFunction
andData.Sequence.fromArray
.
0.5.4.0 Jan 2014
-
Bundled with GHC 7.8.1.
-
The
Data.Map.fromList
andData.Set.fromList
now use linear-time algorithm if the input is sorted, without need to callfromDistinctAscList
. -
Implement indexing operations (
lookupIndex
,findIndex
,elemAt
,deletaAt
) forData.Set
too. -
Add
Applicative
andAlternative
instances forData.Sequence
. -
Add
foldMapWithKey
toData.Map
andData.IntMap
. -
Implement poly-kinded
Typeable
. -
Add
Functor
instance forData.Graph.SCC
. -
Add
Data.Map.splitRoot
andData.Set.splitRoot
.
0.5.0.0 May 2012
-
Bundled with GHC 7.6.1.
-
Major improvements since last release:
- a clearer distinction between value-lazy and value-strict containers,
- performance improvements across the board,
- a big internal clean-up, and
- new functions for e.g. merging, updating, and searching containers.
-
While the old
Data.Map
andData.IntMap
modules will continue to exist for the foreseeable future, we’ve abandoned the practice of having the strict and lazy versions of each function distinguished by an apostrophe. The distinction is instead made at the module level, by introducing four new modules:- Data.Map.Strict
- Data.Map.Lazy
- Data.IntMap.Strict
- Data.IntMap.Lazy
This split has three benefits:
- It makes the choice between value-strict and value-lazy containers more declarative; you pick once at import time, instead of having to remember to use the strict or lazy versions of a function every time you modify the container.
- It alleviates a common source of performance issues, by forcing the user to think about the strictness properties upfront. For example, using insertWith instead of insertWith’ is a common source of containers-related performance bugs.
- There are fewer functions per module, making it easier to get an overview of each module.
-
Note that the types used in the strict and lazy APIs are the same, so you can still use the same container in a “mixed” manner, if needed.
-
The
Data.IntSet
representation changed to store small sets using bits in anWord
. Larger sets are stored as a collection of such dense small sets, connected together by a prefix trie.
0.4.2.1 Feb 2012
-
Bundled with GHC 7.4.1.
-
Data.Map now exports
foldr,
foldr’,
foldland
foldl’`. -
Data.Set now exports
foldr,
foldr’,
foldland
foldl’`. -
Data.IntMap now exports
foldr,
foldr’,
foldl,
foldl’,
foldrWithKey,
foldrWithKey’,
foldlWithKeyand
foldlWithKey’`. -
Data.IntSet now exports
foldr,
foldr’,
foldland
foldl’`. -
Data.Map.foldWithKey
is no longer deprecated, although it is expected to be deprecated again in the future. -
There are now
NFData
instance forData.Map.Map
,Data.Set.Set
,Data.IntMap.IntMap
,Data.IntSet.IntSet
andData.Tree.Tree
.
0.4.1.0 Aug 2011
-
Bundled with GHC 7.2.1.
-
Data.Map
now exports new functionsfoldrWithKey'
andfoldlWithKey'
, which are strict variants offoldrWithKey
andfoldlWithKey
respectively. -
Data.IntMap
now exports new functionsinsertWith'
andinsertWithKey'
, which are strict variants ofinsertWith
andinsertWithKey
respectively.
0.4.0.0 Nov 2010
-
Bundled with GHC 7.0.1.
-
Strictness is now more consistent, with containers being strict in their elements even in singleton cases.
-
There is a new function
insertLookupWithKey'
inData.Map
. -
The
foldWithKey
function inData.Map
has been deprecated in favour offoldrWithKey
.
0.3.0.0 Dec 2009
-
Bundled with GHC 6.12.1.
-
mapAccumRWithKey
has been added toData.IntMap
. -
A
Traversable
instance has been added toData.IntMap.IntMap
. -
The types of
Data.IntMap.intersectionWith
andData.IntMap.intersectionWithKey
have been changed fromintersectionWith :: (a -> b -> a) -> IntMap a -> IntMap b -> IntMap a
intersectionWithKey :: (Key -> a -> b -> a) -> IntMap a -> IntMap b -> IntMap a
tointersectionWith :: (a -> b -> c) -> IntMap a -> IntMap b -> IntMap c
intersectionWithKey :: (Key -> a -> b -> c) -> IntMap a -> IntMap b -> IntMap c
-
The types of
Data.IntMap.findMin
andData.IntMap.findMax
have been changed fromfindMin :: IntMap a -> a
findMax :: IntMap a -> a
tofindMin :: IntMap a -> (Int,a)
findMax :: IntMap a -> (Int,a)
-
Data.Map
now exportsmapAccumRWithKey
,foldrWithKey
,foldlWithKey
andtoDescList
. -
Data.Sequence
now exportsreplicate
,replicateA
,replicateM
,iterateN
,unfoldr
,unfoldl
,scanl
,scanl1
,scanr
,scanr1
,tails
,inits
,takeWhileL
,takeWhileR
,dropWhileL
,dropWhileR
,spanl
,spanr
,breakl
,breakr
,partition
,filter
,sort
,sortBy
,unstableSort
,unstableSortBy
,elemIndexL
,elemIndicesL
,elemIndexR
,elemIndicesR
,findIndexL
,findIndicesL
,findIndexR
,findIndicesR
,foldlWithIndex
,foldrWithIndex
,mapWithIndex
,zip
,zipWith
,zip3
,zipWith3
,zip4
andzipWith4
.
0.2.0.0 Nov 2008
-
Bundled with GHC 6.10.1.
-
Various result type now use
Maybe
rather than allowing anyMonad
.
0.1.0.0 Nov 2007
-
Bundled with GHC 6.8.1.
-
Initial split off from GHC base.