Skip to content

Instantly share code, notes, and snippets.

@Vagabond
Last active January 6, 2016 03:22
Show Gist options
  • Save Vagabond/08ef49ab5b6104c124aa to your computer and use it in GitHub Desktop.
Save Vagabond/08ef49ab5b6104c124aa to your computer and use it in GitHub Desktop.
hashmap_compare_pre(S) ->
S#state.hashmap /= undefined.
hashmap_compare_args(S) ->
[S#state.hashmap].
hashmap_compare(Hashmap) ->
Iter = eqc_c:alloc({struct, iterator_t}),
hashmap:hashmap_iter_begin(Hashmap, Iter),
R = dump_hash(Iter, []),
eqc_c:free(Iter),
R.
hashmap_compare_post(S, [_], R) ->
case lists:sort(S#state.map) == lists:sort(R) of
true ->
true;
false ->
{hash_mismatch, lists:sort(S#state.map), lists:sort(R)}
end.
dump_hash(Iter, Acc) ->
case hashmap:iter_next(Iter) of
'NULL' ->
Acc;
Ptr ->
Pair = eqc_c:deref(eqc_c:cast_ptr({struct, hashmap_pair_t}, Ptr)),
Key = eqc_c:read_array(eqc_c:cast_ptr(unsigned_char, Pair#hashmap_pair_t.key), Pair#hashmap_pair_t.keylen),
Val = eqc_c:read_array(eqc_c:cast_ptr(unsigned_char, Pair#hashmap_pair_t.val), Pair#hashmap_pair_t.vallen),
dump_hash(Iter, [{Key, Val}|Acc])
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment