Re: Map of vectors how? <Long>

From: Larry Brasfield (donotspam_larry_brasfield_at_hotmail.com)
Date: 11/22/04


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. 


Relevant Pages

  • Re: GCC question
    ... terminated (a C string) or not) and again one int (where I decide ... be able to calculate the correct size of the data structure. ... because the padding is also done when the ascii ...
    (comp.lang.c)
  • Re: How to do multiple VM Mappings to the same RAM page?
    ... a maps to 0x60000000, and the page is set to PROT_NONE ... The first method that occurs to me is to use file-backed mmap. ... with sysv shm you could shmget a segment and then shmat it 3 times. ... int main ...
    (comp.os.linux.development.system)
  • Re: Map of vectors how? <Long>
    ... > I've been working with the STL Containers for a little while now, ... > wanted to modify my frequency tables, so far I have been using maps like: ... int all; ...
    (comp.lang.cpp)
  • Container
    ... is there something like container in Matlab e.g. Maps or ... I want a map with String int. ... I can rebuild it ...
    (comp.soft-sys.matlab)
  • Re: [9fans] MIPS LSB compiler
    ... a container of an arbitrary type. ... The bytes.Map function maps ... a function from int to int over an array (or slice? ... function that maps a function from int to float over an array ...
    (comp.os.plan9)