diff options
author | Hans Bolinder <[email protected]> | 2015-05-12 14:15:40 +0200 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2015-05-18 09:04:52 +0200 |
commit | f584a60d0e5a6fa0a8002a13e8dda2a790031427 (patch) | |
tree | 6d5056ad30a2920c68f64aae6d5e046f70210f73 /lib/stdlib/src | |
parent | ddc4e717df1da722682b6ccdbf152a6b7e15f378 (diff) | |
download | otp-f584a60d0e5a6fa0a8002a13e8dda2a790031427.tar.gz otp-f584a60d0e5a6fa0a8002a13e8dda2a790031427.tar.bz2 otp-f584a60d0e5a6fa0a8002a13e8dda2a790031427.zip |
stdlib: Add gb_sets:iterator_from
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r-- | lib/stdlib/src/gb_sets.erl | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/stdlib/src/gb_sets.erl b/lib/stdlib/src/gb_sets.erl index 393fb07229..d3fbd542f7 100644 --- a/lib/stdlib/src/gb_sets.erl +++ b/lib/stdlib/src/gb_sets.erl @@ -137,6 +137,10 @@ %% approach is that it does not require the complete list of all %% elements to be built in memory at one time. %% +%% - iterator_from(X, S): returns an iterator that can be used for +%% traversing the elements of set S greater than or equal to X; +%% see `next'. +%% %% - next(T): returns {X, T1} where X is the smallest element referred %% to by the iterator T, and T1 is the new iterator to be used for %% traversing the remaining elements, or the atom `none' if no @@ -157,8 +161,8 @@ insert/2, add/2, delete/2, delete_any/2, balance/1, union/2, union/1, intersection/2, intersection/1, is_disjoint/2, difference/2, is_subset/2, to_list/1, from_list/1, from_ordset/1, smallest/1, - largest/1, take_smallest/1, take_largest/1, iterator/1, next/1, - filter/2, fold/3, is_set/1]). + largest/1, take_smallest/1, take_largest/1, iterator/1, + iterator_from/2, next/1, filter/2, fold/3, is_set/1]). %% `sets' compatibility aliases: @@ -500,6 +504,22 @@ iterator({_, L, _} = T, As) -> iterator(nil, As) -> As. +-spec iterator_from(Element, Set) -> Iter when + Set :: set(Element), + Iter :: iter(Element). + +iterator_from(S, {_, T}) -> + iterator_from(S, T, []). + +iterator_from(S, {K, _, T}, As) when K < S -> + iterator_from(S, T, As); +iterator_from(_, {_, nil, _} = T, As) -> + [T | As]; +iterator_from(S, {_, L, _} = T, As) -> + iterator_from(S, L, [T | As]); +iterator_from(_, nil, As) -> + As. + -spec next(Iter1) -> {Element, Iter2} | 'none' when Iter1 :: iter(Element), Iter2 :: iter(Element). |