Robot Dreams

Entries tagged as algorithms

Thursday, February 23. 2006

Set, Query, Result

First off, a general update. It's been a slow start to the blog, sorry about that. But I'm still recovering from a total drive failure of the machine I do most of my development work from. So it's been a hard slog to reinstall everything, especially that initial Windows install with at least 15 reboots (I was counting them and that's when I gave up). On to the subject at hand...

One of the data structures in C++ I make use of most are the associative standard containers. I use them because of the bounded algorithmic guarantees they provide. But one of the most nagging problems with them is that it is hard to do any meaningful searching once one has arranged to keep the sorted elements. Sure it's easy to find equivalent elements with for example std::set::equal_range. But if how you are sorting is anything but the element itself as a value it's rather painful to come up with the usual convoluted special value elements to do the searching for you. For example having:

struct A
{
    int type;
    std::string label;
    std::string description;
};

struct S
{
    bool operator()(
        boost::shared_ptr<A> const & a,
        boost::shared_ptr<A> const & b ) const
    {
        return a->type < b->type;
    }
};

std::multiset<boost::shared_ptr<A>,S> db;

And wanting to find out how many A's of type #2 there are. So even though the set is arrange in the most optimal way for getting that answer one is thwarted in using the property of the set only because std::multiset::count, and others, don't take anything but the an element.


Continue reading "Set, Query, Result"

Posted by Rene Rivera in Programming at 21:19 Comments (0) Trackbacks (0)
Defined tags for this entry: algorithms, boost, c++, programming
(Page 1 of 1, totaling 1 entries)

Calendar

Back March '10
Mon Tue Wed Thu Fri Sat Sun
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

Archives

March 2010
February 2010
January 2010
Recent...
Older...

Categories

XML Diversions
XML Life
XML Meta
XML News
XML Politics
XML Programming



All categories

Show tagged entries

aspenxml
autostitchxml
boostxml
c++xml
cameraxml
chicagoxml
conferencexml
doorxml
drinkingxml
evanstonxml
hardwarexml
hawaiixml
kauaixml
liberalxml
panoramaxml
photoxml
planexml
politicsxml
programmingxml
robotxml
torontoxml
travelxml
weatherxml

Quicksearch

Syndicate This Blog

XML RSS 1.0 feed
XML RSS 2.0 feed
ATOM/XML ATOM 1.0 feed

Other

  • Blogrolls...
  • Blogroll Me!
  • Subscribe with Bloglines