Skip to content

Commit 372cc2e

Browse files
committed
Back out "Always use first syncmer as base"
This backs out commit 9fa9d41.
1 parent 7557b6d commit 372cc2e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/randstrobes.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ static inline syncmer_hash_t syncmer_smer_hash(uint64_t packed) {
4949
* This function combines two individual syncmer hashes into a single hash
5050
* for the randstrobe.
5151
*
52-
* One syncmer is designated as the "main", the other is the "auxiliary".
52+
* The syncmer with the smaller hash is designated as the "main", the other is
53+
* the "auxiliary".
5354
* The combined hash is obtained by setting the top bits to the bits of
5455
* the main hash and the bottom bits to the bits of the auxiliary
5556
* hash. Since entries in the index are sorted by randstrobe hash, this allows
@@ -58,6 +59,10 @@ static inline syncmer_hash_t syncmer_smer_hash(uint64_t packed) {
5859
static inline randstrobe_hash_t randstrobe_hash(
5960
syncmer_hash_t hash1, syncmer_hash_t hash2, randstrobe_hash_t main_hash_mask
6061
) {
62+
// Make the function symmetric
63+
if (hash1 > hash2) {
64+
std::swap(hash1, hash2);
65+
}
6166
return ((hash1 & main_hash_mask) | (hash2 & ~main_hash_mask)) & RANDSTROBE_HASH_MASK;
6267
}
6368

@@ -156,11 +161,12 @@ std::ostream& operator<<(std::ostream& os, const QueryRandstrobe& randstrobe) {
156161
}
157162

158163
Randstrobe make_randstrobe(Syncmer strobe1, Syncmer strobe2, randstrobe_hash_t main_hash_mask) {
164+
bool first_strobe_is_main = strobe1.hash < strobe2.hash;
159165
return Randstrobe{
160166
randstrobe_hash(strobe1.hash, strobe2.hash, main_hash_mask),
161167
static_cast<uint32_t>(strobe1.position),
162168
static_cast<uint32_t>(strobe2.position),
163-
true
169+
first_strobe_is_main
164170
};
165171
}
166172

0 commit comments

Comments
 (0)