我想创造这样的东西,就像这里解释的那样。
using IntervalTrees
# Create an interval tree mapping (Int, Int) intervals to Strings.
xs = IntervalMap{Int, ASCIIString}()
# Insert values
xs[(1,100)] = "Low"
xs[(101,1000)] = "Medium"
xs[(1001,10000)] = "High"
# Search for values
println(xs[(1001,10000)]) # prints "High"
# Get a value, returning a default value if not found
println(get(xs, (10001, 100000), "Not found")) # prints "Not found"
# Set a value if it's not already present
println(set(xs, (10001, 100000), "Not found"))
# Delete values
delete!(xs, (1,100))
然而,而不是映射到字符串。我想映射到一个数组。所以我尝试了这样的事情。
intmap = IntervalMap{Int, Array{SubString{String},1}}
但这会返回:
ERROR: LoadError: MethodError: no method matching setindex!(::Type{IntervalTrees.IntervalBTree{Int64,IntervalTrees.IntervalValue{Int64,Array{SubString{String},1}},64}}, ::Array{SubString{String},1}, ::Tuple{SubString{String},SubString{String}})
有没有办法实现这一目标?