Re: Process arbitrary #lists (continued)



David Frank wrote:

"LR" <lruss@xxxxxxxxxxxxx> wrote in message news:44fee5e0$0$6841$cc2e38e6@xxxxxxxxxxxxxxxxx

David Frank wrote:


Otoh, your solution seems to be growing like topsy,
kinda like the long incomprehensible (to me) C++ solution

Yes, to you, but not incomprehensible to anyone who knows C++.

I think what you might have meant was: "the gloriously elegant C++ solution".



Well lets have a look at your glorious solution thats MORE than twice
the statements of my solution.

But it does more. And I think it does it better. For example, there's no need for me to have to read in an entire file so I can check how many lists there are before I can allocate space for them. std::map will do that for me, no worries.

BTW, is it possible for you to do this without having to read in the entire file twice, or without having to read the entire file to see how many entries you'll need before you allocate them?

Also, in C++ if you do have a file in memory someplace (at least in a string) you can read from it as if it were a stream. Can you do this in Fortran? If so, how would you encode the end of line?


http://home.earthlink.net/~dave_gemini/list.cpp

If you're going to post it, you could at least maintain the original indentation. To not do that kind of prejudices things, wouldn't you say?



As far as I can tell you are NOT creating a data structure that contains ALL
the indexable lists. (your MX variable holding 1 list isnt an array?)

No, the MX type
(typedef std::map<std::string, std::vector<int> > MX;)
can hold multiple lists each indexed by a string. A std::map is something like an associative array.

An MX is a map that is indexed by strings and has as data a vector of type int.

Of course, my solution writes and reads several files and holds it all in memory. You seem to have overlooked that, but the typedef that has

typedef std::map<std::string, MX> XX; // yeah a bad name.

allows a map that is indexed by a string that holds as value an instance of an MX.

I bet no PLI'er here understands your code, but if they want to migrate to C++
instead of migrating to Fortran, I cant think of a worse punishment to inflict
on these maroons.

I don't think they want to migrate. I think you might want to migrate.

Let me clarify std::map for you a little bit, David.

Here's a little snippet.

std::vector<int> v1, v2;
v1.push_back(43);
v1.push_back(52);

v2.push_back(78);
v2.push_back(92);

std::map<std::string, std::vector<int> > m;
m["This"] = v1;
m["that"] = v2;

Is that clearer?

std::map is usually implemented as a Red-Black tree. And you're not limited to indexing by string. You can use int if you want. You can use std::vector or even std::set

eg std::map< std::set<int>, SomeUserDefinedClass>

Personally, I think that generics are handled a little bit better in C++ than they are in Fortran. Although of course, YMWV.

David, you may find this of interest
http://www.dinkumware.com/manuals/
http://www.dinkumware.com/manuals/?manual=compleat&page=map.html

HTH.



[snip]

LR
.



Relevant Pages

  • TOC of Python Cookbook now online (was Re: author index for Python Cookbook 2?)
    ... Processing a String One Character at a Time ... Finding a File on the Python Search Path ... Constructing Lists with List Comprehensions ... Looping over Items and Their Indices in a Sequence ...
    (comp.lang.python)
  • ANN: MeObjects Library for Delphi
    ... object type small and powerful. ... the Object instance can use the ClassType method return the ... Especially for lists of pointers to dynamically allocated memory. ... {Summary Adds Ansi String and correspondent object to a list. ...
    (borland.public.delphi.thirdpartytools.general)
  • Filling a grid with Sharepoint data
    ... /// Retrieves a Lists web service proxy with default settings. ... string strComputerName = System.Net.Dns.GetHostName.ToLower; ... XmlDocument xmlDoc, ... XmlElement elementMethod, ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Code for List Boxes
    ... I also had to add a closing parentheses to strWhere = ... Dim strWhere As String ... Dim varSelected As Variant ... when you've selected values from the two lists? ...
    (microsoft.public.access.modulesdaovba)
  • Re: Can Dir handle different file types?
    ... Dim list As String ... Public Function ListFiles(Paths As String, Patterns As String, Optional ListCount As Long = 0) As String ... Dim pathIndex As Long, patternIndex As Long, listPosition As Long ... ' Accept lists that start with up to 2 delimiters ...
    (microsoft.public.vb.general.discussion)