Last active
October 1, 2015 06:28
-
-
Save clr/1937161 to your computer and use it in GitHub Desktop.
Set Intersection ErlangGames
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
-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