Skip to content

Commit

Permalink
Precompute ExactSearchQuery faster (#305)
Browse files Browse the repository at this point in the history
Compute bshift and fshift in one pass instead of two.
  • Loading branch information
jakobnissen authored May 28, 2024
1 parent 18d70d5 commit e9633fc
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/search/ExactSearchQuery.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,22 @@ function ExactSearchQuery(pat::BioSequence, comparator::Function = isequal)
return T(comparator, pat, UInt64(0), 0, 0)
end

first = pat[1]
last = pat[end]
first = @inbounds pat[1]
last = @inbounds pat[end]
bloom_mask = zero(UInt64)
fshift = bshift = m
set_bshift = true

for i in 1:lastindex(pat)
x = pat[i]
for (i, x) in enumerate(pat)
bloom_mask |= _bloom_bits(typeof(comparator), x)
if comparator(x, last) && i < m
fshift = m - i
end
end

for i in lastindex(pat):-1:1
x = pat[i]
if comparator(x, first) && i > 1
if set_bshift && i > 1 && comparator(x, first)
bshift = i - 1
set_bshift = false
end
end

return T(comparator, pat, bloom_mask, fshift, bshift)
end

Expand Down

0 comments on commit e9633fc

Please sign in to comment.