Skip to content

Instantly share code, notes, and snippets.

@TransGirlCodes
Last active March 15, 2017 14:38
Show Gist options
  • Save TransGirlCodes/1c550e345b742f3287da4f9a2c2fda08 to your computer and use it in GitHub Desktop.
Save TransGirlCodes/1c550e345b742f3287da4f9a2c2fda08 to your computer and use it in GitHub Desktop.
Parameterising MinHashSketch
# From this:
type MinHashSketch
sketch::Vector{UInt64}
kmersize::Int
function MinHashSketch(sketch::Vector, kmersize::Int)
length(sketch) > 0 || error("Sketch cannot be empty")
kmersize > 0 || error("Kmersize must be greater than 0")
new(sketch, kmersize)
end
end
# To this:
type MinHashSketch{k}
sketch::Vector{UInt64}
function MinHashSketch{k}(sketch::Vector)
length(sketch) > 0 || error("Sketch cannot be empty")
k > 0 || error("Kmersize must be greater than 0") # This could even be reworked into a generated function, or I believe more complex "where" syntax is comming to parametric functions.
new(sketch, kmersize)
end
end
# With k as a type parameter, you can do MinHashSketch{10}(myvector), and some descisions about K size can be relegated to compile time with generated functions, or otherwise removes the need to pass k as a value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment