summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2019-11-18 17:39:15 +0100
committernsensfel <SpamShield0@noot-noot.org>2019-11-18 17:39:15 +0100
commit8d7c8ffee198155a70cf5131ec4bb1f3d70a5891 (patch)
tree493ba17ee06181718569df32f918f3c46bca57df /src
parent3fb30b108828e3ad6bf811c0f3372a79ec6e9595 (diff)
...
Diffstat (limited to 'src')
-rw-r--r--src/shared/util/shr_orddict_util.erl50
1 files changed, 50 insertions, 0 deletions
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.