Saturday 15 March 2014

data structures - Hierarchical filtered lookup in C++ -


I'm focusing on the problem of a data structure for a while, but did not come up with a good solution. I can not realize that the solution is simple and I am not seeing it, though, hope that you can help!

Here's the problem: I have a large collection of items to remember. Each of them has several data fields Some data fields, such as IDs, are unique to each object, but others, such as names, may appear in multiple objects.

  class object {size_t id; Std :: string name; Histogram Histogram; type kind; ...};   

I need to organize these things in such a way that I will get permission quickly (even if the number of items is relatively large, i.e. lakhs), an arbitrary number of object members, For example, if all the members who have been left unspecified as wildcards, for example, if I specify a specified name then I want to recover all those items. So I namely equal to the name of the member. However, if I add a histogram to the query, then I would like to return the query only to objects that match both the name and the histogram , and Similarly Therefore, for example, I would like a function

  std :: set & lt; Object * & gt;   

Both can retrieve (42, wildcard, wildcard, type)

received

Additionally retrieve (42, wildcard, wildcard, type_foo) , (

Where the second call will return less or even equally as many objects as to what data structure allows such questions and both of the millions In not the appropriate time for the object count to build and can be asked?

Thanks for the help!

First you apply the efficiency of differnt members on your object Can use for This can help to limit the number of elements that may be considered. As a second step, to get the first element or to copy all the elements to use std :: copy_if You can use only Lambda expressions to implement a uniform for std :: find_if . Target Sequence If you decide to promote, then you can use Boost Range.

No comments:

Post a Comment