summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anderson <ejona86@gmail.com>2014-07-03 13:58:12 -0700
committerEric Anderson <ejona86@gmail.com>2014-07-03 13:58:12 -0700
commit35e0024a8dcd074de8879545847721c983a087b2 (patch)
tree90017001e87c0a2238d13ebe9f7ca620ef89f451
parent0ca2d12dc6aa86b9908938159b307491c70eb1ef (diff)
downloadcapset-35e0024a8dcd074de8879545847721c983a087b2.tar.gz
capset-35e0024a8dcd074de8879545847721c983a087b2.zip
Add comments to bitwise matching
-rw-r--r--capset.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/capset.go b/capset.go
index 3fcc814..ae77571 100644
--- a/capset.go
+++ b/capset.go
@@ -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 {