Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > stl data structure to represent a tree

Reply
Thread Tools

stl data structure to represent a tree

 
 
puzzlecracker
Guest
Posts: n/a
 
      09-18-2005
I am looking for a data structure or perhaps a container that I can use
to represent linux-like file system (each node in the tree containes
needed fields, i.e. permissions, d/f, etc: for this I am thing of
mapping node to a structure.. any commetns about this).


Any suggestions (other then implementing my own tree)?
Thanks

 
Reply With Quote
 
 
 
 
Daw
Guest
Posts: n/a
 
      09-18-2005
Maybe you can make a structure like

struct FS {
// permissions, d/f etc.
};

and then use some container like

std::vector<FS> nodes;

 
Reply With Quote
 
 
 
 
puzzlecracker
Guest
Posts: n/a
 
      09-18-2005
I am thinking to have something like this:

struct Entry{

union {
std::stringBuffer info; // dont remembe the exact equivalent for
sting buffer
std::vector<Entry>;
}type;


};
what is the best way to distinguesh the current content of the union?

thx

 
Reply With Quote
 
puzzlecracker
Guest
Posts: n/a
 
      09-18-2005
I forgot that unions have some issues with nontrivial ctors...

so here my another attempt


struct Entry{

all flags shared by directory and files



};


struct FileEntry:Entry{

string buffer

};



struct DirEntry:Entry{

vector<Entry> ve;

};

I am thing along this lines..


I am also considering forwarding approach... any pro/cons?

 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      09-19-2005
puzzlecracker wrote:
> I forgot that unions have some issues with nontrivial ctors...
>
> so here my another attempt
>
>
> struct Entry{
>
> all flags shared by directory and files
>
>
>
> };
>
>
> struct FileEntry:Entry{
>
> string buffer
>
> };
>
>
>
> struct DirEntry:Entry{
>
> vector<Entry> ve;
>
> };
>
> I am thing along this lines..
>
>
> I am also considering forwarding approach... any pro/cons?
>


Your code above suffers from slicing, you need pointers (or possible
smart pointers).

struct DirEntry:Entry{

vector<Entry*> ve;

};

You need to read up on polymorphism, which is what you are heading
towards above.

I'm not sure what you mean by a forwarding approach.

john
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hi, I want to implement a General Tree Data structure (Not Binary Tree ) which have more than 2 sub nodes? sharan C Programming 2 10-31-2007 02:58 AM
Hi, I want to implement a General Tree Data structure (Not Binary Tree ) which have more than 2 sub nodes? sharan C Programming 1 10-30-2007 11:01 PM
Hi, I want to implement a General Tree Data structure (Not Binary Tree ) which have more than 2 sub nodes? sharan C Programming 4 10-30-2007 08:21 PM
Visual cues to represent lost focus on tree, table, etc. B Young Java 1 11-16-2003 02:45 AM
B tree, B+ tree and B* tree Stub C Programming 3 11-12-2003 01:51 PM



Advertisments