Skip to content

Instantly share code, notes, and snippets.

@clr
Last active October 1, 2015 06:28
Show Gist options
  • Save clr/1937161 to your computer and use it in GitHub Desktop.
Save clr/1937161 to your computer and use it in GitHub Desktop.
Set Intersection ErlangGames
-module(set).
-include_lib("eunit/include/eunit.hrl").
-export([intersection/2]).
intersection_test_() ->
A = large_random_set(100000, 1000000),
B = large_random_set(100000, 1000000),
Result = sets:intersection(A, B),
?_assertEqual(Result, intersection(A, B)).
intersection(A, B) ->
sets:intersection(A, B).
%% helper functions to create big sets of random integers
large_random_set(N, MaxValue) ->
large_random_set(N, MaxValue, sets:new()).
large_random_set(0, _, S) ->
S;
large_random_set(N, MaxValue, S) ->
large_random_set(N - 1, MaxValue, sets:add_element(random:uniform(MaxValue), S)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment