summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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.