1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-09-13 08:25:39 +02:00

more economical generate_balls using Base.product

This commit is contained in:
kalmarek 2017-11-05 14:58:58 +01:00
parent d6befc7990
commit 78881e1d79

View File

@ -378,28 +378,12 @@ end
#
###############################################################################
function products{T<:GroupElem}(X::AbstractVector{T}, Y::AbstractVector{T}, op=*)
result = Vector{T}()
seen = Set{T}()
for x in X
for y in Y
z = op(x,y)
if !in(z, seen)
push!(seen, z)
push!(result, z)
end
end
end
return result
end
function generate_balls{T<:GroupElem}(S::Vector{T}, Id::T; radius=2, op=*)
sizes = Vector{Int}()
S = deepcopy(S)
S = unshift!(S, Id)
function generate_balls{T<:GroupElem}(S::Vector{T}, Id::T=parent(first(S))(); radius=2, op=*)
sizes = Int[]
B = [Id]
for i in 1:radius
B = products(B, S, op);
BB = [op(i,j) for (i,j) in Base.product(B,S)]
B = unique([B; vec(BB)])
push!(sizes, length(B))
end
return B, sizes