Skip to content

Commit 70aaf40

Browse files
committed
change to mergeDataEntries, and fixes
1 parent fec5ce5 commit 70aaf40

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/DataBlobs/services/AbstractDataEntries.jl

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,16 @@ function getDataEntry(var::AbstractDFGVariable, blobId::UUID)
4444
error("No dataEntry with blobId $(blobId) found in variable $(getLabel(var))")
4545
end
4646

47-
getDataEntry(dfg::AbstractDFG, label::Symbol, key::Union{Symbol,UUID}) = getDataEntry(getVariable(dfg, label), key)
47+
getDataEntry(dfg::AbstractDFG, label::Symbol, key::UUID) = getDataEntry(getVariable(dfg, label), key)
48+
getDataEntry(dfg::AbstractDFG, label::Symbol, key::Symbol) = getDataEntry(getVariable(dfg, label), key)
4849

4950

5051
"""
5152
$(SIGNATURES)
5253
Add Data Entry to a DFG variable
5354
Should be extended if DFG variable is not returned by reference.
5455
55-
Also see: [`getDataEntry`](@ref), [`addDataBlob`](@ref), [`copyDataEntry!`](@ref)
56+
Also see: [`getDataEntry`](@ref), [`addDataBlob`](@ref), [`mergeDataEntries!`](@ref)
5657
"""
5758
function addDataEntry!(var::AbstractDFGVariable, bde::AbstractDataEntry)
5859
haskey(var.dataDict, bde.label) && error("Data entry $(bde.label) already exists in variable $(getLabel(var))")
@@ -181,14 +182,34 @@ in a source variable.
181182
182183
See also: [`addDataEntry!`](@ref), [`getDataEntry`](@ref), [`listDataEntries`](@ref), [`getDataBlob`](@ref)
183184
"""
184-
function copyDataEntry!(
185+
function mergeDataEntries!(
185186
dst::AbstractDFG,
186187
dlbl::Symbol,
187188
src::AbstractDFG,
188189
slbl::Symbol,
189190
bllb::Union{Symbol, UUID, <:AbstractString, Regex}
190191
)
191192
#
192-
de = getDataEntry(src, slbl, bllb)
193-
addDataEntry!(dst, dlbl, de)
193+
des = getDataEntry(src, slbl, bllb)
194+
# don't add data entries that already exist
195+
dde = listDataEntries(dst, dlbl)
196+
uids = (s->s.id).(dde)
197+
filter!(s -> !(s.id in uids), des)
198+
# add any data entries not already in the destination variable, by uuid
199+
addDataEntry!.(dst, dlbl, des)
200+
end
201+
202+
function mergeDataEntries!(
203+
dst::AbstractDFG,
204+
dlbl::Symbol,
205+
src::AbstractDFG,
206+
slbl::Symbol,
207+
::Colon=:
208+
)
209+
des = listDataEntries(src, slbl)
210+
# don't add data entries that already exist
211+
dde = listDataEntries(dst, dlbl)
212+
uids = (s->s.id).(dde)
213+
filter!(s -> !(s.id in uids), des)
214+
union(((s->mergeDataEntries!(dst, dlbl, src, slbl, s.id)).(des))...)
194215
end

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export copyGraph!, deepcopyGraph, deepcopyGraph!, buildSubgraph, mergeGraph!
197197
export addDataEntry!, getDataEntry, updateDataEntry!, deleteDataEntry!, getDataEntries, listDataEntries, hasDataEntry, hasDataEntry
198198
export listDataEntrySequence
199199
# convenience wrappers
200-
export addDataEntry!, copyDataEntry!
200+
export addDataEntry!, mergeDataEntries!
201201
# aliases
202202
export addData!
203203

0 commit comments

Comments
 (0)