wolffd@0: function C = mysymsetdiff(A,B) wolffd@0: % MYSYMSETDIFF Symmetric set difference of two sets of positive integers (much faster than built-in setdiff) wolffd@0: % C = mysetdiff(A,B) wolffd@0: % C = (A\B) union (B\A) = { things that A and B don't have in common } wolffd@0: wolffd@0: if isempty(A) wolffd@0: ma = 0; wolffd@0: else wolffd@0: ma = max(A); wolffd@0: end wolffd@0: wolffd@0: if isempty(B) wolffd@0: mb = 0; wolffd@0: else wolffd@0: mb = max(B); wolffd@0: end wolffd@0: wolffd@0: if ma==0 wolffd@0: C = B; wolffd@0: elseif mb==0 wolffd@0: C = A; wolffd@0: else % both non-empty wolffd@0: m = max(ma,mb); wolffd@0: bitsA = sparse(1, m); wolffd@0: bitsA(A) = 1; wolffd@0: bitsB = sparse(1, m); wolffd@0: bitsB(B) = 1; wolffd@0: C = find(xor(bitsA, bitsB)); wolffd@0: end