Re: help on Indexing contents in file
- From: "Giovanni Dicanio" <giovanni.dicanio@xxxxxxxxxx>
- Date: Wed, 10 Oct 2007 12:26:22 +0200
"Nash" <jeevs007@xxxxxxxxx> ha scritto nel messaggio
news:1192006852.776581.12020@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thanx for your reply.
You're welcome.
What i was thinking is the format of the file
can be changed to something like this
Category A
2(No of items)
item A1 0
item A3 0
Category B
1(No of items)
item B2 0
so that we can save some memory and also we can directly go to
category insted of parsing all the results.
I think it is a good idea.
Maybe the management is a bit more complicated than the "flat" approach I
suggested in my previous post, because here you are introducing a hierarchy,
so you need also to mantain a new state about the category you are currently
processing.
Frankly speaking, if you want to give some hierarchical organization to your
data, and not just use "flat" data, I would start considering XML...
Using an XML parser for read/write your *hierarchical* data could be easier
than developing a custom binary format and code to process it (it all
depends also from your programming skills, and the level of optimization you
want to achieve...).
You may consider using XML (and an already built XML parser), and then if
you don't like the performances, you may switch to a custom binary format.
While displaying category A items(it may have 10 items for eg) in list
i need to take each item and compare against all the items under
category A to determine the ranking and also while assigning a rank i
need to loop through all the items to find whether it is already rated
if not add a new entry else update the existing one. So what could be
the better aproach for doing that?
If you have these needs of grouping items, you may define a class/structure
to store just Item name and Rank.
And you can define a Category class to store items of that category.
And then you can store all Category instances into a container.
This is a hierarchical approach, and it is good if you need to group items
by category.
You may also consider using std::map instead of std::vector for containers,
if you want to identify the items or categories by their names (the std::map
key would be a string).
Moreover, considering that you are defining a more complex data structure
context to represent your data, you may consider using *pointers* to class
instances (and not stack-based automatic class instances), to avoid
deep-copy. And you can combine STL containers like std::vector or std::map
with boost::shared_ptr, getting kind of a "C++ garbage collector" :)
Giovanni
.
- References:
- Re: help on Indexing contents in file
- From: Joseph M . Newcomer
- Re: help on Indexing contents in file
- From: Nash
- Re: help on Indexing contents in file
- From: Giovanni Dicanio
- Re: help on Indexing contents in file
- From: Nash
- Re: help on Indexing contents in file
- Prev by Date: Re: This calculation is just wrong / computer can't count!
- Next by Date: Re: This calculation is just wrong / computer can't count!
- Previous by thread: Re: help on Indexing contents in file
- Next by thread: Re: help on Indexing contents in file
- Index(es):
Relevant Pages
|