Skip to content

Instantly share code, notes, and snippets.

View digital-carver's full-sized avatar

SundaraRaman R digital-carver

View GitHub Profile
using BenchmarkTools
function bubble_sort(v::AbstractArray{T}) where T<:Real
for _ in 1:length(v)-1
for i in 1:length(v)-1
@inbounds if v[i] > v[i+1]
v[i], v[i+1] = v[i+1], v[i]
end
end
end
@digital-carver
digital-carver / getuniqueindices.jl
Last active October 16, 2022 04:50
Indices of each unique element in an array - threaded
function unique_ids3(itr)
# create individual dictionaries for each thread,
# where keys have the type of itr's elements
d = [Dict{eltype(itr), Vector{Int}}() for _ in 1:Threads.nthreads()]
# iterate through itr, using automatic threading
# :static ensures that threadid() remains constant within an iteration
Threads.@threads :static for index in eachindex(itr)
id = Threads.threadid()
@inbounds val = itr[index]
# check if the dictionary