Last active
January 6, 2016 05:05
-
-
Save Vagabond/a8442281615af74fa9de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hashmap_iter_delete_pre(S) -> | |
S#state.hashmap /= undefined. | |
hashmap_iter_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_iter_delete_args(S) -> | |
[S#state.hashmap, ?SUCHTHAT(X1, eqc_gen:list(eqc_gen:char()), length(X1) > 0)]. | |
hashmap_iter_delete(Hashmap, Key) -> | |
Iter = eqc_c:alloc({struct, iterator_t}), | |
hashmap:hashmap_iter_begin(Hashmap, Iter), | |
R = iter_delete(Hashmap, Iter, Key), | |
eqc_c:free(Iter), | |
R. | |
hashmap_iter_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_iter_delete_next(S, _R, [_, Key]) -> | |
S#state{map=lists:keydelete(Key, 1, S#state.map)}. | |
iter_delete(Hashmap, Iter, Key) -> | |
case hashmap:iter_next(Iter) of | |
'NULL' -> | |
hashmap:hashmap_delete(Hashmap, Iter); | |
Ptr -> | |
Pair = eqc_c:deref(eqc_c:cast_ptr({struct, hashmap_pair_t}, Ptr)), | |
IterKey = eqc_c:read_array(eqc_c:cast_ptr(unsigned_char, Pair#hashmap_pair_t.key), Pair#hashmap_pair_t.keylen), | |
case Key == IterKey of | |
true -> | |
hashmap:hashmap_delete(Hashmap, Iter); | |
false -> | |
iter_delete(Hashmap, Iter, Key) | |
end | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment