1
0
mirror of https://github.com/kalmarek/GroupRings.jl.git synced 2024-11-14 21:25:28 +01:00

Typed reverse Dict

This commit is contained in:
kalmarek 2018-04-09 13:03:10 +02:00
parent 1074d4e849
commit 725493afc0

View File

@ -521,11 +521,13 @@ function rationalize{T<:Integer, S<:Number}(::Type{T}, X::GroupRingElem{S};
return GroupRingElem(v, parent(X))
end
function reverse_dict(iter)
T = eltype(iter)
return Dict{T, Int}(x => i for (i,x) in enumerate(iter))
function reverse_dict(::Type{I}, iter) where I<:Integer
length(iter) > typemax(I) && error("Can not produce reverse dict: $(length(iter)) is too large for $T")
return Dict{eltype(iter), I}(x => i for (i,x) in enumerate(iter))
end
reverse_dict(iter) = reverse_dict(UInt, iter)
function create_pm{T<:GroupElem}(basis::Vector{T}, basis_dict::Dict{T, Int},
limit::Int=length(basis); twisted::Bool=false, check=true)
product_matrix = zeros(Int, (limit,limit))