Re: Map of vectors how? <Long>
From: Larry Brasfield (donotspam_larry_brasfield_at_hotmail.com)
Date: 11/22/04
- Next message: Peter Koch Larsen: "Re: About c++ pointer"
- Previous message: m_at_j3R ;: "Re: Plugin-able application"
- In reply to: Juicer_X: "Map of vectors how? <Long>"
- Next in thread: Juicer_X: "Re: Map of vectors how? <Long>"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 22 Nov 2004 00:54:10 -0800
"Juicer_X" <brentaritchie@yahoo.ca> wrote in message news:10q317bd2l8ila7@corp.supernews.com...
> Hello everyone,
>
> I've been working with the STL Containers for a little while now, but in the middle of working on a small "Markov Chain" class
> I realized that I wanted to modify my frequency tables, so far I have been using maps like:
>
> std::map<std::string, int> frequency;
>
> A string for the letter combinations and an int for the frequency, but now I want to add three more frequencies:
>
> 1. how many times a letter combination starts a word.
> 2. how many times a letter combination ends a word.
> 3. how many times a letter combination is used within a word.
>
> I thought about using a vector within a map but I've no idea how to use such a data structure?
>
> I know that it has to be declared like so:
>
> std::map<std::string, vector<int>*> frequency;
>
> But how would I add or find data within this container?
Why not do something like the following?
struct WordStats {
int matchesCount;
int startsWithCount;
int endsWithCount;
int isFoundInCount;
WordStats() : matchesCount(0), startsWithCount(0), endsWithCount(0), isFoundInCount(0) {}
};
std::map<std::string, WordStats> frequency;
Then you would add or access mappings thusly:
WordStats & ws = frequency[std::string("someWord")];
switch (matchKind) }
case matchAll: ++ws.matchesCount; break;
case startsOnly: ++ws.startsWithCount; break;
case endsOnly: ++ws.endsWithCount; break;
case isWithin: ++ws.isFoundInCount; break;
}
> Here is some sample code so you know what I'm trying to do:
[Cut for space.]
> Thank you for taking the time to read.
OK.
-- --Larry Brasfield email: donotspam_larry_brasfield@hotmail.com Above views may belong only to me.
- Next message: Peter Koch Larsen: "Re: About c++ pointer"
- Previous message: m_at_j3R ;: "Re: Plugin-able application"
- In reply to: Juicer_X: "Map of vectors how? <Long>"
- Next in thread: Juicer_X: "Re: Map of vectors how? <Long>"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|