Skip to content

Instantly share code, notes, and snippets.

@Vagabond
Last active January 6, 2016 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vagabond/479602ba9bd3a59155f9 to your computer and use it in GitHub Desktop.
Save Vagabond/479602ba9bd3a59155f9 to your computer and use it in GitHub Desktop.
hashmap_delete_pre(S) ->
S#state.hashmap /= undefined.
hashmap_delete_args(S = #state{map=Map}) when length(Map) > 0 ->
[S#state.hashmap,
eqc_gen:oneof([eqc_gen:elements(element(1, lists:unzip(S#state.map))),
?SUCHTHAT(X1, eqc_gen:list(eqc_gen:char()), length(X1) > 0)])];
hashmap_delete_args(S) ->
[S#state.hashmap, ?SUCHTHAT(X1, eqc_gen:list(eqc_gen:char()), length(X1) > 0)].
hashmap_delete(Hashmap, Key) ->
KeyStr = eqc_c:create_string(Key),
R = hashmap:hashmap_del(Hashmap, KeyStr, length(Key)),
eqc_c:free(KeyStr),
R.
hashmap_delete_post(S, [_, Key], R) ->
%% check the return code against whether the key was in the map
case lists:keyfind(Key, 1, S#state.map) of
{Key, _} ->
R == 0;
false ->
R == 1
end.
hashmap_delete_next(S, _R, [_, Key]) ->
S#state{map=lists:keydelete(Key, 1, S#state.map)}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment