From a1c796e7f6b86b4b506492ae6354382c565278d1 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Thu, 12 Oct 2017 16:00:50 +0200 Subject: 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. --- lib/stdlib/doc/src/maps.xml | 52 ++++----------------------------------------- 1 file changed, 4 insertions(+), 48 deletions(-) (limited to 'lib/stdlib/doc') 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 @@

An iterator representing the key value associations in a map.

-

Created using maps:iterator/1 - and maps:iterator/2.

+

Created using maps:iterator/1.

Consumed by maps:next/1, maps:filter/2, maps:fold/3 and @@ -194,9 +193,9 @@ false

Returns a map iterator Iterator that can be used by maps:next/1 - to traverse the keys and values in a map. This call is equivalent - to calling maps:iterator/2 - with an empty map as the options.

+ 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.

The call fails with a {badmap,Map} exception if Map is not a map.

Example:

@@ -214,49 +213,6 @@ none
- - - Create a map iterator. - -

Returns a map iterator Iterator that can - be used by maps:next/1 - to traverse the keys and values in a map. The iterator will behave - according to the given Opts.

- - optimize - - Configures whether the iterator should be optimized for speed - or for memory consumption. Default is speed. - - ordered - - Configures whether the iterator should return the key value - associations ordered on the keys according to erlang term order - or not. The default is false. - - -

Both options can be configured at the same time.

-

The call fails with a {badmap,Map} exception if - Map is not a map.

-

Example:

- -> 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} -
-
- -- cgit v1.2.3