Skip to content

Commit 54b7abc

Browse files
committed
refactor treeindex_map
1 parent fff2d5a commit 54b7abc

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/fusiontrees/fusiontreeblocks.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,18 @@ numind(::Type{T}) where {T<:FusionTreeBlock} = numin(T) + numout(T)
5454
fusiontrees(block::FusionTreeBlock) = block.trees
5555
Base.length(block::FusionTreeBlock) = length(fusiontrees(block))
5656

57+
function treeindex_map(fs::FusionTreeBlock)
58+
I = sectortype(fs)
59+
return fusiontreedict(I)(f => ind for (ind, f) in enumerate(fusiontrees(fs)))
60+
end
61+
62+
5763
# Manipulations
5864
# -------------
5965
function transformation_matrix(transform, dst::FusionTreeBlock{I},
6066
src::FusionTreeBlock{I}) where {I}
6167
U = zeros(sectorscalartype(I), length(dst), length(src))
62-
indexmap = Dict(f => ind for (ind, f) in enumerate(fusiontrees(dst)))
68+
indexmap = treeindex_map(dst)
6369
for (col, f) in enumerate(fusiontrees(src))
6470
for (f′, c) in transform(f)
6571
row = indexmap[f′]
@@ -80,7 +86,7 @@ function bendright(src::FusionTreeBlock)
8086
@assert N₁ > 0
8187

8288
dst = FusionTreeBlock{I}(uncoupled_dst, isdual_dst)
83-
indexmap = fusiontreedict(I)(f => ind for (ind, f) in enumerate(fusiontrees(dst)))
89+
indexmap = treeindex_map(dst)
8490
U = zeros(sectorscalartype(I), length(dst), length(src))
8591

8692
for (col, (f₁, f₂)) in enumerate(fusiontrees(src))
@@ -139,7 +145,7 @@ function bendleft(src::FusionTreeBlock)
139145
@assert N₁ > 0
140146

141147
dst = FusionTreeBlock{I}(uncoupled_dst, isdual_dst)
142-
indexmap = fusiontreedict(I)(f => ind for (ind, f) in enumerate(fusiontrees(dst)))
148+
indexmap = treeindex_map(dst)
143149
U = zeros(sectorscalartype(I), length(dst), length(src))
144150

145151
for (col, (f₂, f₁)) in enumerate(fusiontrees(src))
@@ -196,7 +202,7 @@ function foldright(src::FusionTreeBlock)
196202
dst = FusionTreeBlock{sectortype(src)}(uncoupled_dst, isdual_dst)
197203

198204
dst = FusionTreeBlock{I}(uncoupled_dst, isdual_dst)
199-
indexmap = fusiontreedict(I)(f => ind for (ind, f) in enumerate(fusiontrees(dst)))
205+
indexmap = treeindex_map(dst)
200206
U = zeros(sectorscalartype(I), length(dst), length(src))
201207

202208
for (col, (f₁, f₂)) in enumerate(fusiontrees(src))
@@ -265,7 +271,7 @@ function foldleft(src::FusionTreeBlock)
265271
@assert N₁ > 0
266272

267273
dst = FusionTreeBlock{I}(uncoupled_dst, isdual_dst)
268-
indexmap = fusiontreedict(I)(f => ind for (ind, f) in enumerate(fusiontrees(dst)))
274+
indexmap = treeindex_map(dst)
269275
U = zeros(sectorscalartype(I), length(dst), length(src))
270276

271277
for (col, (f₂, f₁)) in enumerate(fusiontrees(src))

0 commit comments

Comments
 (0)