From 8d7c8ffee198155a70cf5131ec4bb1f3d70a5891 Mon Sep 17 00:00:00 2001 From: nsensfel Date: Mon, 18 Nov 2019 17:39:15 +0100 Subject: ... --- src/shared/util/shr_orddict_util.erl | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/shared/util/shr_orddict_util.erl diff --git a/src/shared/util/shr_orddict_util.erl b/src/shared/util/shr_orddict_util.erl new file mode 100644 index 0000000..7f290cc --- /dev/null +++ b/src/shared/util/shr_orddict_util.erl @@ -0,0 +1,50 @@ +-module(shr_orddict_util). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-export +( + [ + compute_next_non_neg_integer_index/1 + ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec compute_next_non_neg_integer_index + ( + orddict:orddict(non_neg_integer(), any()) + ) + -> non_neg_integer(). +compute_next_non_neg_integer_index (Collection) -> + CollectionSize = orddict:size(Collection), + Candidates = lists:seq(0, CollectionSize), + + Result = + lists:foldr + ( + fun (Candidate, CurrentResult) -> + case is_integer(CurrentResult) of + true -> CurrentResult; + false -> + case orddict:is_key(Candidate, Collection) of + true -> none; + false -> Candidate + end + end + end, + none, + Candidates + ), + + Result. -- cgit v1.2.3-70-g09d2