Mercurial > hg > mauch-mirex-2010
annotate _FullBNT/KPMtools/mysymsetdiff.m @ 9:4ea6619cb3f5 tip
removed log files
author | matthiasm |
---|---|
date | Fri, 11 Apr 2014 15:55:11 +0100 |
parents | b5b38998ef3b |
children |
rev | line source |
---|---|
matthiasm@8 | 1 function C = mysymsetdiff(A,B) |
matthiasm@8 | 2 % MYSYMSETDIFF Symmetric set difference of two sets of positive integers (much faster than built-in setdiff) |
matthiasm@8 | 3 % C = mysetdiff(A,B) |
matthiasm@8 | 4 % C = (A\B) union (B\A) = { things that A and B don't have in common } |
matthiasm@8 | 5 |
matthiasm@8 | 6 if isempty(A) |
matthiasm@8 | 7 ma = 0; |
matthiasm@8 | 8 else |
matthiasm@8 | 9 ma = max(A); |
matthiasm@8 | 10 end |
matthiasm@8 | 11 |
matthiasm@8 | 12 if isempty(B) |
matthiasm@8 | 13 mb = 0; |
matthiasm@8 | 14 else |
matthiasm@8 | 15 mb = max(B); |
matthiasm@8 | 16 end |
matthiasm@8 | 17 |
matthiasm@8 | 18 if ma==0 |
matthiasm@8 | 19 C = B; |
matthiasm@8 | 20 elseif mb==0 |
matthiasm@8 | 21 C = A; |
matthiasm@8 | 22 else % both non-empty |
matthiasm@8 | 23 m = max(ma,mb); |
matthiasm@8 | 24 bitsA = sparse(1, m); |
matthiasm@8 | 25 bitsA(A) = 1; |
matthiasm@8 | 26 bitsB = sparse(1, m); |
matthiasm@8 | 27 bitsB(B) = 1; |
matthiasm@8 | 28 C = find(xor(bitsA, bitsB)); |
matthiasm@8 | 29 end |