Skip to content

Commit 8684a69

Browse files
Reduce edge4pair Dict size by half by using sorted uv's
1 parent 669680a commit 8684a69

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/topologies/halfedge.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ function HalfEdgeTopology(halves::AbstractVector{Tuple{HalfEdge,HalfEdge}})
122122
edge4pair = Dict{Tuple{Int,Int},Int}()
123123
for (i, (h₁, h₂)) in enumerate(ordered)
124124
u, v = h₁.head, h₂.head
125-
edge4pair[(u, v)] = i
126-
edge4pair[(v, u)] = i
125+
edge4pair[minmax(u, v)] = i
127126
end
128127

129128
HalfEdgeTopology(halfedges, half4elem, half4vert, edge4pair)
@@ -208,10 +207,9 @@ function HalfEdgeTopology(elems::AbstractVector{<:Connectivity}; sort=true)
208207
halves = Vector{Tuple{HalfEdge,HalfEdge}}()
209208
visited = Set{Tuple{Int,Int}}()
210209
for ((u, v), he) in half4pair
211-
if (u, v) ∉ visited
210+
if minmax(u, v) ∉ visited
212211
push!(halves, (he, he.half))
213-
push!(visited, (u, v))
214-
push!(visited, (v, u))
212+
push!(visited, minmax(u, v))
215213
end
216214
end
217215

@@ -294,14 +292,14 @@ vertices `uv`.
294292

295293
Always return the half-edge to the "left".
296294
"""
297-
half4pair(t::HalfEdgeTopology, uv::Tuple{Int,Int}) = half4edge(t, t.edge4pair[uv])
295+
half4pair(t::HalfEdgeTopology, uv::Tuple{Int,Int}) = half4edge(t, edge4pair(t, uv))
298296

299297
"""
300298
edge4pair(t, uv)
301299

302300
Return the edge of the half-edge topology `t` for the pair of vertices `uv`.
303301
"""
304-
edge4pair(t, uv) = t.edge4pair[uv]
302+
edge4pair(t, uv) = t.edge4pair[minmax(uv...)]
305303

306304
# ---------------------
307305
# HIGH-LEVEL INTERFACE

0 commit comments

Comments
 (0)