Hello, I need a fast and simple search for an object by field value, like in a database.
search for an object with the maximum field value,
search by object field value
search object with next value up
What data structure can i use for this?
May be i should create a list or dict for searching fields?
Put your objects in a array and use findfirst, findmax etc. If you need better than O(n), you’ll something else, such as a tree.
Databases are fast because they index various columns then can use those index to find the correct row (object) in the database quickly. I haven’t really run into any package that maintains multiple indexes on a set of objects so you can quickly find the object you want based on some criteria.
You could probably create a custom object using the structures in:
function Base.push!(c::Collection, v::Foo)
if haskey(c.lookup1, v.value1) || haskey(c.lookup2, v.value2)
throw("Foo is not unique")
c.lookup1[v.value1] = length(c.data)
c.lookup2[v.value2] = length(c.data)
You would have to take a look at the documentation of Datastructures.jl it gives you methods to iterate over the SortedDict objects in key order.