Mercurial > hg > camir-aes2014
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function C = mysymsetdiff(A,B) | |
2 % MYSYMSETDIFF Symmetric set difference of two sets of positive integers (much faster than built-in setdiff) | |
3 % C = mysetdiff(A,B) | |
4 % C = (A\B) union (B\A) = { things that A and B don't have in common } | |
5 | |
6 if isempty(A) | |
7 ma = 0; | |
8 else | |
9 ma = max(A); | |
10 end | |
11 | |
12 if isempty(B) | |
13 mb = 0; | |
14 else | |
15 mb = max(B); | |
16 end | |
17 | |
18 if ma==0 | |
19 C = B; | |
20 elseif mb==0 | |
21 C = A; | |
22 else % both non-empty | |
23 m = max(ma,mb); | |
24 bitsA = sparse(1, m); | |
25 bitsA(A) = 1; | |
26 bitsB = sparse(1, m); | |
27 bitsB(B) = 1; | |
28 C = find(xor(bitsA, bitsB)); | |
29 end |