@@ -46,7 +46,7 @@ function assertHash(de::BlobEntry, db; hashfunction::Function = sha256)
46
46
end
47
47
48
48
49
- function Base. show (io:: IO , entry:: BlobEntry )
49
+ function Base. show (io:: IO , :: MIME"text/plain" , entry:: BlobEntry )
50
50
println (io, " _type=BlobEntry {" )
51
51
println (io, " id: " , entry. id)
52
52
println (io, " blobId: " , entry. blobId)
@@ -62,10 +62,6 @@ function Base.show(io::IO, entry::BlobEntry)
62
62
println (io, " }" )
63
63
end
64
64
65
- Base. show (io:: IO , :: MIME"text/plain" , entry:: BlobEntry ) = show (io, entry)
66
-
67
-
68
-
69
65
# #==============================================================================
70
66
# # BlobEntry - CRUD
71
67
# #==============================================================================
85
81
86
82
function getBlobEntry (var:: AbstractDFGVariable , blobId:: UUID )
87
83
for (k,v) in var. dataDict
88
- # FIXME stop using v.id since that has been repurposed for unique BlobEntry indexing
89
- if v. originId == blobId || v. blobId == blobId || v. id == blobId
84
+ if blobId in [v. originId, v. blobId]
90
85
return v
91
86
end
92
87
end
@@ -95,9 +90,15 @@ function getBlobEntry(var::AbstractDFGVariable, blobId::UUID)
95
90
)
96
91
end
97
92
98
- # TODO consider changing this to use `first` as in julia's findfirst - as in findfirstBlobEntry->label::Symbol
99
- # or getBlobEntryFirst, btw this returns a vector in some other places
100
- function getBlobEntry (var:: AbstractDFGVariable , key:: Regex )
93
+ @deprecate getBlobEntry (var:: AbstractDFGVariable , key:: Regex ) getBlobEntryFirst (var, key)
94
+
95
+ """
96
+ $(SIGNATURES)
97
+ Finds and returns the first blob entry that matches the regex.
98
+
99
+ Also see: [`getBlobEntry`](@ref)
100
+ """
101
+ function getBlobEntryFirst (var:: AbstractDFGVariable , key:: Regex )
101
102
for (k,v) in var. dataDict
102
103
if occursin (key, string (v. label))
103
104
return v
110
111
111
112
getBlobEntry (var:: AbstractDFGVariable , key:: AbstractString ) = getBlobEntry (var,Regex (key))
112
113
113
-
114
+ # TODO split betweeen getfirstBlobEntry and getBlobEntry
114
115
getBlobEntry (dfg:: AbstractDFG , label:: Symbol , key:: Union{Symbol, UUID, <:AbstractString, Regex} ) = getBlobEntry (getVariable (dfg, label), key)
115
116
# getBlobEntry(dfg::AbstractDFG, label::Symbol, key::Symbol) = getBlobEntry(getVariable(dfg, label), key)
116
117
@@ -125,22 +126,30 @@ Also see: [`getBlobEntry`](@ref), [`addBlob!`](@ref), [`mergeBlobEntries!`](@ref
125
126
function addBlobEntry! (
126
127
var:: AbstractDFGVariable ,
127
128
entry:: BlobEntry ;
128
- blobId:: Union{UUID,Nothing} = (isnothing (entry. blobId) ? entry. id : entry. blobId),
129
- blobSize:: Int = (hasfield (BlobEntry, :size ) ? entry. size : - 1 )
130
129
)
131
130
# see https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/985
131
+ # blobId::Union{UUID,Nothing} = (isnothing(entry.blobId) ? entry.id : entry.blobId),
132
+ # blobSize::Int = (hasfield(BlobEntry, :size) ? entry.size : -1)
132
133
haskey (var. dataDict, entry. label) && error (" blobEntry $(entry. label) already exists on variable $(getLabel (var)) " )
133
134
var. dataDict[entry. label] = entry
134
135
return entry
135
136
end
136
137
138
+ function addBlobEntry! (
139
+ var:: PackedVariable ,
140
+ entry:: BlobEntry ,
141
+ )
142
+ entry. label in getproperty .(var. blobEntries,:label ) && error (" blobEntry $(entry. label) already exists on variable $(getLabel (var)) " )
143
+ push! (var. blobEntries, entry)
144
+ return entry
145
+ end
146
+
137
147
function addBlobEntry! (
138
148
dfg:: AbstractDFG ,
139
149
vLbl:: Symbol ,
140
150
entry:: BlobEntry ;
141
- kw...
142
151
)
143
- return addBlobEntry! (getVariable (dfg, vLbl), entry; kw ... )
152
+ return addBlobEntry! (getVariable (dfg, vLbl), entry)
144
153
end
145
154
146
155
@@ -200,18 +209,62 @@ hasBlobEntry(var::AbstractDFGVariable, blobLabel::Symbol) = haskey(var.dataDict,
200
209
201
210
"""
202
211
$(SIGNATURES)
203
- Get data entries, Vector{BlobEntry}
212
+
213
+ Get blob entries, Vector{BlobEntry}
204
214
"""
205
215
function getBlobEntries (var:: AbstractDFGVariable )
206
216
# or should we return the iterator, Base.ValueIterator{Dict{Symbol,BlobEntry}}?
207
217
collect (values (var. dataDict))
208
218
end
219
+
220
+ function getBlobEntries (var:: PackedVariable )
221
+ var. blobEntries
222
+ end
223
+
209
224
function getBlobEntries (dfg:: AbstractDFG , label:: Symbol )
210
225
# !isVariable(dfg, label) && return nothing
211
226
# or should we return the iterator, Base.ValueIterator{Dict{Symbol,BlobEntry}}?
212
227
getBlobEntries (getVariable (dfg, label))
213
228
end
214
229
230
+ function getBlobEntries (dfg:: AbstractDFG , label:: Symbol , regex:: Regex )
231
+ entries = getBlobEntries (dfg, label)
232
+ return filter (entries) do e
233
+ occursin (regex, string (e. label))
234
+ end
235
+ end
236
+
237
+
238
+ """
239
+ $(SIGNATURES)
240
+
241
+ Get all blob entries matching a Regex pattern over variables
242
+
243
+ Notes
244
+ - Use `dropEmpties=true` to not include empty lists in result.
245
+ - Use keyword `varList` for which variables to search through.
246
+ """
247
+ function getBlobEntriesVariables (
248
+ dfg:: AbstractDFG ,
249
+ bLblPattern:: Regex ;
250
+ varList:: AbstractVector{Symbol} = sort (listVariables (dfg); lt= natural_lt),
251
+ dropEmpties:: Bool = false
252
+ )
253
+ RETLIST = Vector {Vector{BlobEntry}} ()
254
+ @showprogress " Get entries matching $bLblPattern " for vl in varList
255
+ bes = filter (
256
+ s-> occursin (bLblPattern,string (s. label)),
257
+ listBlobEntries (dfg,vl)
258
+ )
259
+ # only push to list if there are entries on this variable
260
+ (! dropEmpties || 0 < length (bes)) ? nothing : continue
261
+ push! (RETLIST, bes)
262
+ end
263
+
264
+ return RETLIST
265
+ end
266
+
267
+
215
268
"""
216
269
$(SIGNATURES)
217
270
List the blob entries associated with a particular variable.
0 commit comments