diff options
author | Eric Anderson <ejona86@gmail.com> | 2014-07-03 13:58:12 -0700 |
---|---|---|
committer | Eric Anderson <ejona86@gmail.com> | 2014-07-03 13:58:12 -0700 |
commit | 35e0024a8dcd074de8879545847721c983a087b2 (patch) | |
tree | 90017001e87c0a2238d13ebe9f7ca620ef89f451 | |
parent | 0ca2d12dc6aa86b9908938159b307491c70eb1ef (diff) | |
download | capset-35e0024a8dcd074de8879545847721c983a087b2.tar.gz capset-35e0024a8dcd074de8879545847721c983a087b2.zip |
Add comments to bitwise matching
-rw-r--r-- | capset.go | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -144,11 +144,16 @@ func (d *Deck) hasSetWithLast(tableau []Card) bool { } i := len(tableau) - 1 for j := 0; j < i; j++ { + // Both same and diff are trying to get 11 for each attribute to indicate a + // match. same := ^(tableau[i].attrs ^ tableau[j].attrs) diff := tableau[i].attrs ^ tableau[j].attrs for k := j + 1; k < i; k++ { + // same and diff become fully computed. 11 indicates match. sameFinal := same & ^(tableau[i].attrs ^ tableau[k].attrs) diffFinal := diff ^ tableau[k].attrs + // Shift and AND so that we have a single bit to indicate success. This is + // necessary for the OR to function appropriately. sameSingle := sameFinal & (sameFinal >> 1) diffSingle := diffFinal & (diffFinal >> 1) if (sameSingle|diffSingle)&d.isSetBitMask == d.isSetBitMask { |