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

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function C = mysymsetdiff(A,B)
wolffd@0 2 % MYSYMSETDIFF Symmetric set difference of two sets of positive integers (much faster than built-in setdiff)
wolffd@0 3 % C = mysetdiff(A,B)
wolffd@0 4 % C = (A\B) union (B\A) = { things that A and B don't have in common }
wolffd@0 5
wolffd@0 6 if isempty(A)
wolffd@0 7 ma = 0;
wolffd@0 8 else
wolffd@0 9 ma = max(A);
wolffd@0 10 end
wolffd@0 11
wolffd@0 12 if isempty(B)
wolffd@0 13 mb = 0;
wolffd@0 14 else
wolffd@0 15 mb = max(B);
wolffd@0 16 end
wolffd@0 17
wolffd@0 18 if ma==0
wolffd@0 19 C = B;
wolffd@0 20 elseif mb==0
wolffd@0 21 C = A;
wolffd@0 22 else % both non-empty
wolffd@0 23 m = max(ma,mb);
wolffd@0 24 bitsA = sparse(1, m);
wolffd@0 25 bitsA(A) = 1;
wolffd@0 26 bitsB = sparse(1, m);
wolffd@0 27 bitsB(B) = 1;
wolffd@0 28 C = find(xor(bitsA, bitsB));
wolffd@0 29 end