Skip to content

Commit

Permalink
drop Memoize
Browse files Browse the repository at this point in the history
  • Loading branch information
iblislin committed Oct 20, 2018
1 parent 9262ce7 commit b430429
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
1 change: 0 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
julia 0.7
RecipesBase 0.2.3
Memoize
22 changes: 14 additions & 8 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,33 +146,39 @@ end
find_dupes_index(A::Vector{Symbol}) =
@inbounds [i for i in eachindex(A) if A[i] A[1:i-1]]

@memoize function gen_colnames(n::Integer)
ret = Vector{Symbol}(undef, n)
gen_colnames(n::Integer) = gen_colnames(Val{n}())

@generated function gen_colnames(v::Val{N}) where {N}
ret = Vector{Symbol}(undef, N)

s = ""
for i 1:n
for i 1:N
s = carry_char(s)
ret[i] = Symbol(s)
end

ret
end

@memoize function carry_char(s::String = "")
if s == ""
return "A"
end
const carry_char_cache = Dict{String,String}(
"" => "A",
)
function carry_char(s::String = "")
ret = get(carry_char_cache, s, "")
(ret != "") && return ret

n = length(s)

c = s[n] + 1

if c > 'Z'
ret = if c > 'Z'
c = 'A'
carry_char(s[1:n-1]) * c
else
s[1:n-1] * c
end

carry_char_cache[s] = ret
end

# helper method for `getindex`
Expand Down

0 comments on commit b430429

Please sign in to comment.