Boost logo

Boost Users :

Subject: [Boost-users] [Flyweight] Enumerating all values in the factory?
From: mailinglists (mailinglists_at_[hidden])
Date: 2009-06-26 02:30:22


Hi, thanks for the flyweight library, looks good.

Is there a way to enumerate all values in a factory? Consider my use case:

I have a large set of data. Each element has a user defined 'tag',
implemented as a flyweight<std::string>. Now the user wants to find all
elements where the 'tag' matches a regex.

Calculating the regex match for all elements in the dataset is
expensive. If I could find all matching tags in the flyweight factory
first, searching the elements is reduced to comparing two flyweights
rather than doing a regex match.

Consider:

struct data {
   flyweight<std::string> m_tag;
};

vector<data> m_some_data;

The straight forward approach is costly:
for (iterator i=m_some_data.begin();
   i!=m_some_data.end() && regex_match(*i);
  ++i)
  ;

with the regex match calculated for every element in the vector.

A much more efficient solution is to find all elements in the flyweight
factory that match the regex and then compare the flyweights.

vector<flyweight<std::string> >
m_matching_tags=find_matching_flyweights(regex);

Now iterating over the data needs to compare two flyweights per data
element which should be a lot faster than doing a regex match.

Is there a way?

Regards

Hajo


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net