diff options
author | Lukas Larsson <[email protected]> | 2017-10-12 16:00:50 +0200 |
---|---|---|
committer | Lukas Larsson <[email protected]> | 2017-11-20 09:57:43 +0100 |
commit | a1c796e7f6b86b4b506492ae6354382c565278d1 (patch) | |
tree | b83738b3d313a2c43bdcaf25b555a8c4602492c2 /lib/stdlib/doc/src | |
parent | 0149a73d15df1f80cb46752ec3829f48c38dd230 (diff) | |
download | otp-a1c796e7f6b86b4b506492ae6354382c565278d1.tar.gz otp-a1c796e7f6b86b4b506492ae6354382c565278d1.tar.bz2 otp-a1c796e7f6b86b4b506492ae6354382c565278d1.zip |
erts: Implement batching maps:iterator
This iterator implementation fetches multiple elements to
iterate over in one call to erts_internal:maps_next instead
of one at a time. This means that the memory usage will go
up for the iterator as we are buffering elements, but the
usage is still bounded.
In this implementation the max memory usage is 1000 words.
Using this approach makes the iterator as fast as using
maps:to_list, so maps:iterator/2 has been removed.
Diffstat (limited to 'lib/stdlib/doc/src')
-rw-r--r-- | lib/stdlib/doc/src/maps.xml | 52 |
1 files changed, 4 insertions, 48 deletions
diff --git a/lib/stdlib/doc/src/maps.xml b/lib/stdlib/doc/src/maps.xml index a3afbf8e7f..987d92989d 100644 --- a/lib/stdlib/doc/src/maps.xml +++ b/lib/stdlib/doc/src/maps.xml @@ -38,8 +38,7 @@ <name name="iterator"/> <desc> <p>An iterator representing the key value associations in a map.</p> - <p>Created using <seealso marker="#iterator-1"><c>maps:iterator/1</c></seealso> - and <seealso marker="#iterator-2"><c>maps:iterator/2</c></seealso>.</p> + <p>Created using <seealso marker="#iterator-1"><c>maps:iterator/1</c></seealso>.</p> <p>Consumed by <seealso marker="#next-1"><c>maps:next/1</c></seealso>, <seealso marker="#filter-2"><c>maps:filter/2</c></seealso>, <seealso marker="#fold-3"><c>maps:fold/3</c></seealso> and @@ -194,9 +193,9 @@ false</code> <desc> <p>Returns a map iterator <c><anno>Iterator</anno></c> that can be used by <seealso marker="#next-1"><c>maps:next/1</c></seealso> - to traverse the keys and values in a map. This call is equivalent - to calling <seealso marker="#iterator-2"><c>maps:iterator/2</c></seealso> - with an empty map as the options.</p> + to traverse the key-value associations in a map. When iterating + over a map, the memory usage is guaranteed to be bounded no matter + the size of the map.</p> <p>The call fails with a <c>{badmap,Map}</c> exception if <c><anno>Map</anno></c> is not a map.</p> <p><em>Example:</em></p> @@ -215,49 +214,6 @@ none</code> </func> <func> - <name name="iterator" arity="2"/> - <fsummary>Create a map iterator.</fsummary> - <desc> - <p>Returns a map iterator <c><anno>Iterator</anno></c> that can - be used by <seealso marker="#next-1"><c>maps:next/1</c></seealso> - to traverse the keys and values in a map. The iterator will behave - according to the given <c><anno>Opts</anno></c>.</p> - <taglist> - <tag>optimize</tag> - <item> - Configures whether the iterator should be optimized for <c>speed</c> - or for <c>memory</c> consumption. Default is <c>speed</c>. - </item> - <tag>ordered</tag> - <item> - Configures whether the iterator should return the key value - associations ordered on the keys according to erlang term order - or not. The default is <c>false</c>. - </item> - </taglist> - <p>Both options can be configured at the same time.</p> - <p>The call fails with a <c>{badmap,Map}</c> exception if - <c><anno>Map</anno></c> is not a map.</p> - <p><em>Example:</em></p> - <code type="none"> -> M = maps:from_list([{I,I} || I <- lists:seq(1,50)]). -#{45 => 45,6 => 6,2 => 2,49 => 49,41 => 41,33 => 33,42 => 42, - 43 => 43,10 => 10,9 => 9,19 => 19,14 => 14,5 => 5,18 => 18, - 31 => 31,22 => 22,29 => 29,21 => 21,27 => 27,24 => 24, - 47 => 47,40 => 40,30 => 30,23 => 23,28 => 28,46 => 46, - 16 => 16,38 => 38,4 => 4,...} -> MemoryIter = maps:iterator(M, #{ optimize => memory }), ok. -ok -> {K1, V1, _} = maps:next(MemoryIter), {K1, V1}. -{46,46} -> OrderedIter = maps:iterator(M, #{ ordered => true, optimize => memory }), ok. -ok -> {K2, V2, _} = maps:next(OrderedIter), {K2, V2}. -{1,1}</code> - </desc> - </func> - - <func> <name name="keys" arity="1"/> <fsummary></fsummary> <desc> |