annotate toolboxes/FullBNT-1.0.7/KPMtools/mysymsetdiff.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function C = mysymsetdiff(A,B)
Daniel@0 2 % MYSYMSETDIFF Symmetric set difference of two sets of positive integers (much faster than built-in setdiff)
Daniel@0 3 % C = mysetdiff(A,B)
Daniel@0 4 % C = (A\B) union (B\A) = { things that A and B don't have in common }
Daniel@0 5
Daniel@0 6 if isempty(A)
Daniel@0 7 ma = 0;
Daniel@0 8 else
Daniel@0 9 ma = max(A);
Daniel@0 10 end
Daniel@0 11
Daniel@0 12 if isempty(B)
Daniel@0 13 mb = 0;
Daniel@0 14 else
Daniel@0 15 mb = max(B);
Daniel@0 16 end
Daniel@0 17
Daniel@0 18 if ma==0
Daniel@0 19 C = B;
Daniel@0 20 elseif mb==0
Daniel@0 21 C = A;
Daniel@0 22 else % both non-empty
Daniel@0 23 m = max(ma,mb);
Daniel@0 24 bitsA = sparse(1, m);
Daniel@0 25 bitsA(A) = 1;
Daniel@0 26 bitsB = sparse(1, m);
Daniel@0 27 bitsB(B) = 1;
Daniel@0 28 C = find(xor(bitsA, bitsB));
Daniel@0 29 end