Skip to content

Added exclamation marks to mutating julia functions #526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contents/bogo_sort/code/julia/bogo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ function is_sorted(a::Vector{Float64})
return true
end

function bogo_sort(a::Vector{Float64})
function bogo_sort!(a::Vector{Float64})
while(!is_sorted(a))
shuffle!(a)
end
end

function main()
a = [1, 3, 2, 4]
bogo_sort(a)
a = [1.0, 3.0, 2.0, 4.0]
bogo_sort!(a)
println(a)
end

Expand Down
4 changes: 2 additions & 2 deletions contents/bubble_sort/code/julia/bubble.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function bubble_sort(a::Vector{Float64})
function bubble_sort!(a::Vector{Float64})
n = length(a)
for i = 1:n
for j = 1:n-1
Expand All @@ -12,7 +12,7 @@ end

function main()
a = [1., 3, 2, 4, 5, 10, 50, 7, 1.5, 0.3]
bubble_sort(a)
bubble_sort!(a)
println(a)
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function gaussian_elimination(A::Array{Float64,2})
function gaussian_elimination!(A::Array{Float64,2})

rows = size(A,1)
cols = size(A,2)
Expand Down Expand Up @@ -64,7 +64,7 @@ function back_substitution(A::Array{Float64,2})
end


function gauss_jordan_elimination(A::Array{Float64,2})
function gauss_jordan_elimination!(A::Array{Float64,2})

rows = size(A,1)
cols = size(A,2)
Expand Down Expand Up @@ -97,10 +97,10 @@ function main()
1 2 3 4;
3 -4 0 10]

gaussian_elimination(A)
gaussian_elimination!(A)
println(A)

gauss_jordan_elimination(A)
gauss_jordan_elimination!(A)
println(A)

soln = back_substitution(A)
Expand Down
4 changes: 2 additions & 2 deletions contents/graham_scan/code/julia/graham.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function ccw(a::Point, b::Point, c::Point)
return ((b.x - a.x)*(c.y - a.y) - (b.y - a.y)*(c.x - a.x))
end

function graham_scan(points::Vector{Point})
function graham_scan!(points::Vector{Point})
N = length(points)

# Place the lowest point at the start of the array
Expand Down Expand Up @@ -51,7 +51,7 @@ function main()
Point(-1,-1), Point(-10,11), Point(-6,15), Point(-6,-8), Point(15,-9),
Point(7,-7), Point(-2,-9), Point(6,-5), Point(0,14), Point(2,8)
]
hull = graham_scan(points)
hull = graham_scan!(points)
println(hull)
end

Expand Down
10 changes: 5 additions & 5 deletions contents/huffman_encoding/code/julia/huffman.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ const Node = Union{Leaf, Branch}
isbranch(branch::Branch) = true
isbranch(other::T) where {T} = false

function codebook_recurse(leaf::Leaf, code::String,
function codebook_recurse!(leaf::Leaf, code::String,
dict::Dict{Char,String})
dict[leaf.key] = code
end

function codebook_recurse(branch::Branch, code::String,
function codebook_recurse!(branch::Branch, code::String,
dict::Dict{Char,String})
codebook_recurse(branch.left, string(code, "1"), dict)
codebook_recurse(branch.right, string(code, "0"), dict)
codebook_recurse!(branch.left, string(code, "1"), dict)
codebook_recurse!(branch.right, string(code, "0"), dict)
end

# This will depth-first search through the tree
Expand All @@ -33,7 +33,7 @@ end
# This outputs encoding Dict to be used for encoding
function create_codebook(n::Node)
codebook = Dict{Char,String}()
codebook_recurse(n, "", codebook)
codebook_recurse!(n, "", codebook)
return codebook
end

Expand Down
6 changes: 3 additions & 3 deletions contents/split-operator_method/code/julia/split_op.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function init(par::Param, voffset::Float64, wfcoffset::Float64)
end

# Function for the split-operator loop
function split_op(par::Param, opr::Operators)
function split_op!(par::Param, opr::Operators)

for i = 1:par.timesteps
# Half-step in real space
Expand Down Expand Up @@ -126,7 +126,7 @@ function calculate_energy(par, opr)
energy_final = 0
for i = 1:length(energy_k)
energy_final += real(energy_k[i] + energy_r[i])
end
end

return energy_final*par.dx
end
Expand All @@ -137,7 +137,7 @@ function main()

# Starting wavefunction slightly offset so we can see it change
opr = init(par, 0.0, -1.00)
split_op(par, opr)
split_op!(par, opr)

energy = calculate_energy(par, opr)
println("Energy is: ", energy)
Expand Down