Skip to content

Commit eac347d

Browse files
committed
tags as a set seperate commit so you can just undo it if you don't like. we can get the same behavour with accessors, but we cant garentee that someone will not use v.tags directly. At least union!([:a,:b], [:a]) == [:a, :b] holds so I don't think it will matter much.
1 parent bd40774 commit eac347d

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

src/Common.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,30 @@ function addTags!(dfg::InMemoryDFGTypes, sym::Symbol, tags::Vector{Symbol})
410410
union!(getTags(getFactor(fg, sym)), tags)
411411
end
412412

413+
414+
"""
415+
$SIGNATURES
416+
417+
Add tag to a variable or factor
418+
"""
419+
addTag!(f::DataLevel0, tag::Symbol) = union!(f.tags,[tag])
420+
421+
422+
"""
423+
$SIGNATURES
424+
425+
Merge tags to the node's tags (variable/factor).
426+
"""
427+
mergeTags!(f::DataLevel0, tags::Vector{Symbol}) = union!(f.tags, tags)
428+
429+
"""
430+
$SIGNATURES
431+
432+
Remove the tags from the node
433+
"""
434+
deleteTags!(f::DataLevel0, tags::Vector{Symbol}) = setdiff!(f.tags, tags)
435+
436+
413437
"""
414438
$SIGNATURES
415439

src/CommonAccessors.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ getTags(v::DataLevel0) = v.tags
2020
"""
2121
$SIGNATURES
2222
23-
Set the tags for a factor.
23+
Set the tags for a node.
2424
"""
2525
function setTags!(f::DataLevel0, tags::Vector{Symbol})
26-
resize!(f.tags, length(tags))
27-
f.tags .= tags
26+
empty!(f.tags)
27+
union!(f.tags, tags)
2828
end
2929

3030
"""

src/entities/DFGFactor.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ Construct a DFG factor given a label.
7070
"""
7171
#TODO _internalId?
7272
DFGFactor{T, S}(label::Symbol, internalId::Int64=0, timestamp::DateTime=now()) where {T, S} =
73-
DFGFactor(label, timestamp, Symbol[], GenericFunctionNodeData{T, S}(), 0, DFGNodeParams(0, internalId), Symbol[])
73+
DFGFactor(label, timestamp, Set{Symbol}(), GenericFunctionNodeData{T, S}(), 0, DFGNodeParams(0, internalId), Symbol[])
7474

7575
DFGFactor(label::Symbol;
7676
timestamp::DateTime=now(),
77-
tags::Vector{Symbol}=Symbol[],
77+
tags::Set{Symbol}=Set{Symbol}(),
7878
data::GenericFunctionNodeData{T, S}=GenericFunctionNodeData{T, S}(),
7979
solvable::Int=0,
8080
_internalId::Int64=0,

src/entities/DFGVariable.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct DFGVariable{T<:InferenceVariable} <: AbstractDFGVariable
2020
timestamp::DateTime
2121
"""Variable tags, e.g [:POSE, :VARIABLE, and :LANDMARK].
2222
Accessors: `getTags`, `addTags!`, and `deleteTags!`"""
23-
tags::tags::Set{Symbol}#Vector{Symbol} #TODO I propose we use a set since tags can't be repeated.
23+
tags::Set{Symbol}#Vector{Symbol} #TODO I propose we use a set since tags can't be repeated.
2424
"""Dictionary of estimates keyed by solverDataDict keys
2525
Accessors: `addEstimate!`, `updateEstimate!`, and `deleteEstimate!`"""
2626
ppeDict::Dict{Symbol, <: AbstractPointParametricEst}
@@ -43,7 +43,7 @@ end
4343
The default DFGVariable constructor.
4444
"""
4545
DFGVariable(label::Symbol, softtype::T;
46-
tags::Vector{Symbol}=Symbol[],
46+
tags::Set{Symbol}=Set{Symbol}(),
4747
estimateDict::Dict{Symbol, <: AbstractPointParametricEst}=Dict{Symbol, MeanMaxPPE}(),
4848
solverDataDict::Dict{Symbol, VariableNodeData{T}}=Dict{Symbol, VariableNodeData{T}}(:default => VariableNodeData{T}()),
4949
smallData::Dict{String, String}=Dict{String, String}(),

test/interfaceTests.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ v2 = DFGVariable(:b, TestInferenceVariable2())
1212
f1 = DFGFactor{Int, :Symbol}(:f1)
1313

1414
#add tags for filters
15-
append!(v1.tags, [:VARIABLE, :POSE])
16-
append!(v2.tags, [:VARIABLE, :LANDMARK])
17-
append!(f1.tags, [:FACTOR])
15+
union!(v1.tags, [:VARIABLE, :POSE])
16+
union!(v2.tags, [:VARIABLE, :LANDMARK])
17+
union!(f1.tags, [:FACTOR])
1818

1919
st1 = TestInferenceVariable1()
2020
st2 = TestInferenceVariable2()
@@ -142,8 +142,8 @@ end
142142
@test getLabel(v1) == v1.label
143143
@test getTags(v1) == v1.tags
144144
testTags = [:ha, :ha23]
145-
@test setTags!(v1, testTags) == testTags
146-
@test getTags(v1) == testTags
145+
@test setTags!(v1, testTags) == Set(testTags)
146+
@test getTags(v1) == Set(testTags)
147147

148148
@test getTimestamp(v1) == v1.timestamp
149149
testTimestamp = now()

0 commit comments

Comments
 (0)