Skip to content

Commit 65a6582

Browse files
committed
Add more Blobentry functions
1 parent ce268d4 commit 65a6582

File tree

4 files changed

+102
-35
lines changed

4 files changed

+102
-35
lines changed

src/DataBlobs/services/BlobEntry.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,21 @@ end
7171
"""
7272
$(SIGNATURES)
7373
Finds and returns the first blob entry that matches the filter.
74-
74+
The result is sorted by `sortby[=getLabel]` and `sortlt[=natural_lt]` before returning the first entry.
7575
Also see: [`getBlobentry`](@ref)
7676
"""
7777
function getfirstBlobentry(
7878
v::AbstractGraphVariable;
7979
labelFilter::Union{Nothing, Function} = nothing,
8080
blobIdFilter::Union{Nothing, Function} = nothing,
81+
sortby::Function = getLabel,
82+
sortlt::Function = natural_lt
8183
)
8284
entries = getBlobentries(v; labelFilter, blobIdFilter)
8385
if isempty(entries)
8486
return nothing
8587
else
86-
return entries[1]
88+
return sort(entries; by = sortby, lt = sortlt)[1]
8789
end
8890
end
8991

src/DistributedFactorGraphs.jl

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export getObservation
116116
##------------------------------------------------------------------------------
117117
export getVariable
118118
export hasVariable
119-
119+
export mergeVariables!
120120
##------------------------------------------------------------------------------
121121
## State
122122
##------------------------------------------------------------------------------
@@ -126,6 +126,7 @@ export getStates
126126
# Factor
127127
##------------------------------------------------------------------------------
128128
export mergeFactor!
129+
export mergeFactors!
129130
export hasFactor
130131

131132
##------------------------------------------------------------------------------
@@ -144,7 +145,9 @@ export getAgentBlobentries
144145

145146
export mergeBlobentries!
146147
export mergeGraphBlobentry!
148+
export mergeGraphBlobentries!
147149
export mergeAgentBlobentry!
150+
export mergeAgentBlobentries!
148151

149152
export deleteGraphBlobentry!
150153
export deleteAgentBlobentry!
@@ -154,10 +157,8 @@ export listGraphBlobentries
154157
export listAgentBlobentries
155158

156159
export hasBlobentry
157-
158-
# TODO not yet implemented in DFG
159-
# addAgentBlobentry!
160-
# addGraphBlobentry!
160+
export hasGraphBlobentry
161+
export hasAgentBlobentry
161162

162163
##------------------------------------------------------------------------------
163164
## Blobstores and Blobs
@@ -199,14 +200,15 @@ export GraphsDFG
199200

200201
# export addBlobentry!, getBlobentry, mergeBlobentry!, deleteBlobentry! # historic for VariableBlobentry
201202
# export addBlobentries!, getBlobentries, mergeBlobentries!, deleteBlobentries!
202-
# TODO first pass progress
203203
# export addGraphBlobentry!, getGraphBlobentry, mergeGraphBlobentry!, deleteGraphBlobentry!
204204
# export addGraphBlobentries!, getGraphBlobentries, mergeGraphBlobentries!, deleteGraphBlobentries!
205205
# export addAgentBlobentry!, getAgentBlobentry, mergeAgentBlobentry!, deleteAgentBlobentry!
206206
# export addAgentBlobentries!, getAgentBlobentries, mergeAgentBlobentries!, deleteAgentBlobentries!
207+
#TODO blob entries not implemented on factors yet
207208
# export addFactorBlobentry!, getFactorBlobentry, mergeFactorBlobentry!, deleteFactorBlobentry!
208209
# export addFactorBlobentries!, getFactorBlobentries, mergeFactorBlobentries!, deleteFactorBlobentries!
209210

211+
# TODO first pass progress
210212
# export addVariableMetadata!, getVariableMetadata, mergeVariableMetadata!, deleteVariableMetadata!
211213
# export addFactorMetadata!, getFactorMetadata, mergeFactorMetadata!, deleteFactorMetadata!
212214
# export addAgentMetadata!, getAgentMetadata, mergeAgentMetadata!, deleteAgentMetadata!
@@ -546,31 +548,6 @@ include("services/DFGFactor.jl")
546548
include("Deprecated.jl")
547549
include("services/CompareUtils.jl")
548550

549-
#FIXME move
550-
function mergeGraphBlobentry!(dfg::GraphsDFG, entry::Blobentry)
551-
refBlobentries(dfg.graph)[getLabel(entry)] = entry
552-
return 1
553-
end
554-
555-
function mergeAgentBlobentry!(dfg::GraphsDFG, entry::Blobentry)
556-
refBlobentries(dfg.agent)[getLabel(entry)] = entry
557-
return 1
558-
end
559-
560-
function mergeGraphBlobentries!(dfg::GraphsDFG, entries::Vector{Blobentry})
561-
cnts = map(entries) do entry
562-
return mergeGraphBlobentry!(dfg, entry)
563-
end
564-
return sum(cnts)
565-
end
566-
567-
function mergeAgentBlobentries!(dfg::GraphsDFG, entries::Vector{Blobentry})
568-
cnts = map(entries) do entry
569-
return mergeAgentBlobentry!(dfg, entry)
570-
end
571-
return sum(cnts)
572-
end
573-
574551
# include("services/Sync.jl")
575552

576553
# Include the FilesDFG API.

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ function mergeVariable!(dfg::GraphsDFG, variable::AbstractGraphVariable)
9191
return 1
9292
end
9393

94-
function mergeVariables!(dfg::GraphsDFG, variables)
95-
cnts = map(mergeVariable!, variables)
94+
function DFG.mergeVariables!(dfg::GraphsDFG, variables)
95+
cnts = map(v->mergeVariable!(dfg, v), variables)
9696
return sum(cnts)
9797
end
9898

@@ -112,6 +112,11 @@ function mergeFactor!(dfg::GraphsDFG, factor::AbstractGraphFactor)
112112
return 1
113113
end
114114

115+
function DFG.mergeFactors!(dfg::GraphsDFG, factors)
116+
cnts = map(f->mergeFactor!(dfg, f), factors)
117+
return sum(cnts)
118+
end
119+
115120
function deleteVariable!(dfg::GraphsDFG, label::Symbol)#::Tuple{AbstractGraphVariable, Vector{<:AbstractGraphFactor}}
116121
if !haskey(dfg.g.variables, label)
117122
throw(LabelNotFoundError("Variable", label))
@@ -592,3 +597,78 @@ function addGraphBlobentries!(fg::GraphsDFG, entries::Vector{Blobentry})
592597
return addGraphBlobentry!(fg, entry)
593598
end
594599
end
600+
601+
function DFG.addAgentBlobentry!(fg::GraphsDFG, entry::Blobentry)
602+
if haskey(fg.agent.blobEntries, entry.label)
603+
throw(LabelExistsError("Blobentry", entry.label))
604+
end
605+
push!(fg.agent.blobEntries, entry.label => entry)
606+
return entry
607+
end
608+
609+
function DFG.addAgentBlobentries!(fg::GraphsDFG, entries::Vector{Blobentry})
610+
return map(entries) do entry
611+
return addAgentBlobentry!(fg, entry)
612+
end
613+
end
614+
615+
function DFG.getAgentBlobentry(fg::GraphsDFG, label::Symbol)
616+
if !haskey(fg.agent.blobEntries, label)
617+
throw(LabelNotFoundError("Blobentry", label))
618+
end
619+
return fg.agent.blobEntries[label]
620+
end
621+
622+
function DFG.getAgentBlobentries(fg::GraphsDFG; labelFilter::Union{Nothing, Function} = nothing)
623+
entries = collect(values(fg.agent.blobEntries))
624+
filterDFG!(entries, labelFilter, getLabel)
625+
return entries
626+
end
627+
628+
function DFG.mergeGraphBlobentry!(dfg::GraphsDFG, entry::Blobentry)
629+
refBlobentries(dfg.graph)[getLabel(entry)] = entry
630+
return 1
631+
end
632+
633+
function DFG.mergeAgentBlobentry!(dfg::GraphsDFG, entry::Blobentry)
634+
refBlobentries(dfg.agent)[getLabel(entry)] = entry
635+
return 1
636+
end
637+
638+
function DFG.mergeGraphBlobentries!(dfg::GraphsDFG, entries::Vector{Blobentry})
639+
cnts = map(entries) do entry
640+
return mergeGraphBlobentry!(dfg, entry)
641+
end
642+
return sum(cnts)
643+
end
644+
645+
function DFG.mergeAgentBlobentries!(dfg::GraphsDFG, entries::Vector{Blobentry})
646+
cnts = map(entries) do entry
647+
return mergeAgentBlobentry!(dfg, entry)
648+
end
649+
return sum(cnts)
650+
end
651+
652+
function DFG.deleteGraphBlobentry!(dfg::GraphsDFG, label::Symbol)
653+
if !haskey(dfg.graph.blobEntries, label)
654+
throw(LabelNotFoundError("Blobentry", label))
655+
end
656+
delete!(dfg.graph.blobEntries, label)
657+
return 1
658+
end
659+
660+
function DFG.deleteAgentBlobentry!(dfg::GraphsDFG, label::Symbol)
661+
if !haskey(dfg.agent.blobEntries, label)
662+
throw(LabelNotFoundError("Blobentry", label))
663+
end
664+
delete!(dfg.agent.blobEntries, label)
665+
return 1
666+
end
667+
668+
function DFG.hasGraphBlobentry(dfg::GraphsDFG, label::Symbol)
669+
return haskey(dfg.graph.blobEntries, label)
670+
end
671+
672+
function DFG.hasAgentBlobentry(dfg::GraphsDFG, label::Symbol)
673+
return haskey(dfg.agent.blobEntries, label)
674+
end

src/services/AbstractDFG.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,15 @@ function getGraphBlobentries end
202202
function addGraphBlobentry! end
203203
function addGraphBlobentries! end
204204
function mergeGraphBlobentry! end
205+
function mergeGraphBlobentries! end
205206
function deleteGraphBlobentry! end
206207

207208
function getAgentBlobentry end
208209
function getAgentBlobentries end
209210
function addAgentBlobentry! end
210211
function addAgentBlobentries! end
211212
function mergeAgentBlobentry! end
213+
function mergeAgentBlobentries! end
212214
function deleteAgentBlobentry! end
213215

214216
function getModelBlobentry end
@@ -222,6 +224,10 @@ function listGraphBlobentries end
222224
function listAgentBlobentries end
223225
function listModelBlobentries end
224226

227+
function hasGraphBlobentry end
228+
function hasAgentBlobentry end
229+
function hasModelBlobentry end
230+
225231
##==============================================================================
226232
## AbstractBlobstore CRUD
227233
##==============================================================================
@@ -369,6 +375,7 @@ otherwise, the variable will be added to the graph.
369375
Implement `mergeVariable!(dfg::AbstractDFG, variable::AbstractGraphVariable)`
370376
"""
371377
function mergeVariable! end
378+
function mergeVariables! end
372379

373380
"""
374381
$(SIGNATURES)
@@ -377,6 +384,7 @@ otherwise, the factor will be added to the graph.
377384
Implement `mergeFactor!(dfg::AbstractDFG, factor::AbstractGraphFactor)`
378385
"""
379386
function mergeFactor! end
387+
function mergeFactors! end
380388

381389
"""
382390
$(SIGNATURES)

0 commit comments

Comments
 (0)