CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #5
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: Can a Hash Table Track Multiple Items of Information?

    Quote Originally Posted by phummon View Post
    Hi everyone,

    Thanks for taking the time to read this post! I'll try to answer your thoughts as directly as I can...

    Lindley, the best example is this: Suppose my raw data is the amount of fruit sold at individual fruit carts all across the country. The data format of one line of the raw data could look like this:

    CART / Apples / Oranges / Bananas / Watermellons / Pears / Mangos / etc.

    So suppose the first few lines of the raw data looked like this:

    00001,0,0,2,0,0,8,...
    00002,0,1,0,0,3,0,...
    00003,0,1,1,4,0,0,...

    This would mean Fruit Cart 00001 sold two bananas and eight mangos, Fruit Cart 00002 sold one orange and three pears, and so on.

    I need to crunch all of this information down into a more compact form. Final output would look like:

    Total Carts: 100,000
    Apples: 3,000,000
    Oranges: 7,000,000
    Bananas: 1,000,000
    Watermellons: 150,000
    Pears: 4,000,000
    Mangos: 3,000,000

    See what I'm trying to do? The most serious limitation I have is I don't know how many fruit carts there are (probably millions, actually) and I also don't know how many types of fruit there are either (probably hundreds of thousands)

    The heart of my question is, "How do I do all this tallying on-the-fly in a hash table?"

    Many thanks all!
    I'd say you know your input, and you know your output, but how you want to process it is still not clear.

    For example, why would you want to store the data into a container to begin with?

    All you need to do is read the carts 1 by 1, and update the "Total Pears Sold" field etc.

    Can I ask you how your input is stored/provided? If it is in a file(s), why don't you just keep it there, and place bits of it at a time into memory?

    PS: The gist of a hash is to have a very very very small signature to an object. By manipulating these tiny signatures, it becomes much easier to find the corresponding objects in a map. Hashes don't actually compress data, they just make it easier to find.
    Last edited by monarch_dodra; May 28th, 2010 at 06:16 PM.
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured