1-
2- # #==============================================================================
3- # # Blobentry - compare
4- # #==============================================================================
5-
6- import Base: ==
7-
8- @generated function == (x:: T , y:: T ) where {T <: Blobentry }
9- return mapreduce (n -> :(x.$ n == y.$ n), (a, b) -> :($ a && $ b), fieldnames (x))
10- end
11-
121# #==============================================================================
132# # Blobentry - common
143# #==============================================================================
@@ -85,49 +74,26 @@ Finds and returns the first blob entry that matches the filter.
8574
8675Also see: [`getBlobentry`](@ref)
8776"""
88- function getfirstBlobentry (var:: AbstractGraphVariable , blobId:: UUID )
89- for (k, v) in var. dataDict
90- if blobId == v. blobId
91- return v
92- end
93- end
94- throw (KeyError (" No blobEntry with blobId $(blobId) found in variable $(getLabel (var)) " ))
95- end
96-
97- function getfirstBlobentry (dfg:: AbstractDFG , label:: Symbol , blobId:: UUID )
98- return getfirstBlobentry (getVariable (dfg, label), blobId)
99- end
100-
101- function getfirstBlobentry (var:: AbstractGraphVariable , key:: Regex )
102- for (k, v) in var. dataDict
103- if occursin (key, string (v. label))
104- return v
105- end
106- end
107- throw (
108- KeyError (
109- " No blobEntry with label matching regex $(key) found in variable $(getLabel (var)) " ,
110- ),
111- )
112- end
113-
114- function getfirstBlobentry (var:: VariableDFG , key:: Regex )
115- firstIdx = findfirst (x -> contains (string (x. label), key), var. blobEntries)
116- if isnothing (firstIdx)
117- throw (KeyError (" $key " ))
77+ function getfirstBlobentry (
78+ v:: AbstractGraphVariable ;
79+ labelFilter:: Union{Nothing, Function} = nothing ,
80+ blobIdFilter:: Union{Nothing, Function} = nothing ,
81+ )
82+ entries = getBlobentries (v; labelFilter, blobIdFilter)
83+ if isempty (entries)
84+ return nothing
85+ else
86+ return entries[1 ]
11887 end
119- return var. blobEntries[firstIdx]
12088end
12189
122- function getfirstBlobentry (dfg:: AbstractDFG , label:: Symbol , key:: Regex )
123- els = listBlobentries (dfg, label)
124- firstIdx = findfirst (contains (key), string .(els))
125- isnothing (firstIdx) && throw (
126- KeyError (
127- " No blobEntry with label matching regex $(key) found in variable $(label) " ,
128- ),
129- )
130- return getBlobentry (dfg, label, els[firstIdx])
90+ function getfirstBlobentry (
91+ dfg:: AbstractDFG ,
92+ label:: Symbol ;
93+ labelFilter:: Union{Nothing, Function} = nothing ,
94+ blobIdFilter:: Union{Nothing, Function} = nothing ,
95+ )
96+ return getfirstBlobentry (getVariable (dfg, label); labelFilter, blobIdFilter)
13197end
13298
13399# TODO Consider autogenerating all methods of the form:
@@ -227,38 +193,49 @@ end
227193
228194Does a blob entry exist with `blobLabel`.
229195"""
230- hasBlobentry (var :: VariableCompute , blobLabel:: Symbol ) = haskey (var . dataDict, blobLabel)
196+ hasBlobentry (v :: VariableCompute , blobLabel:: Symbol ) = haskey (v . dataDict, blobLabel)
231197
232- function hasBlobentry (var :: VariableDFG , label:: Symbol )
233- return label in getproperty .(var . blobEntries, :label )
198+ function hasBlobentry (v :: VariableDFG , label:: Symbol )
199+ return label in getproperty .(v . blobEntries, :label )
234200end
235201
236202"""
237203 $(SIGNATURES)
238204
239205Get blob entries, returns a `Vector{Blobentry}`.
240206"""
241- function getBlobentries (var:: VariableCompute )
242- return collect (values (var. dataDict))
207+ function getBlobentries (v:: VariableCompute )
208+ return collect (values (v. dataDict))
209+ end
210+
211+ function getBlobentries (v:: VariableDFG )
212+ return copy (v. blobEntries)
243213end
244214
245- function getBlobentries (var:: VariableDFG )
246- return var. blobEntries
215+ function getBlobentries (
216+ v:: AbstractGraphVariable ;
217+ labelFilter:: Union{Nothing, Function} = nothing ,
218+ blobIdFilter:: Union{Nothing, Function} = nothing ,
219+ )
220+ entries = getBlobentries (v)
221+ filterDFG! (entries, labelFilter, x -> string (x. label))
222+ filterDFG! (entries, blobIdFilter, x -> string (x. blobId))
223+ return entries
247224end
248225
249226function getBlobentries (
250227 dfg:: AbstractDFG ,
251228 variableLabel:: Symbol ;
252229 labelFilter:: Union{Nothing, Function} = nothing ,
230+ blobIdFilter:: Union{Nothing, Function} = nothing ,
253231)
254- entries = getBlobentries (getVariable (dfg, variableLabel))
255- filterDFG! (entries, labelFilter)
256- return entries
232+ return getBlobentries (getVariable (dfg, variableLabel); labelFilter, blobIdFilter)
257233end
258234
259235function gatherBlobentries (
260236 dfg:: AbstractDFG ;
261237 labelFilter:: Union{Nothing, Function} = nothing ,
238+ blobIdFilter:: Union{Nothing, Function} = nothing ,
262239 solvableFilter:: Union{Nothing, Function} = nothing ,
263240 tagsFilter:: Union{Nothing, Function} = nothing ,
264241 typeFilter:: Union{Nothing, Function} = nothing ,
@@ -272,7 +249,7 @@ function gatherBlobentries(
272249 labelFilter = variableLabelFilter,
273250 )
274251 return map (vls) do vl
275- return getBlobentries (dfg, vl; labelFilter)
252+ return vl => getBlobentries (dfg, vl; labelFilter, blobIdFilter )
276253 end
277254end
278255
0 commit comments