Looking for a C++ class.

J

JustSomeGuy

I need a class that is essentially a matrix (template) class.
I need to be able add rows and columns as needed.
any one know of such a class?
 
V

Victor Bazarov

JustSomeGuy said:
I need a class that is essentially a matrix (template) class.
I need to be able add rows and columns as needed.
any one know of such a class?

Yes, I know of a matrix class (or two, or three). What do you mean
"add rows and columns as needed"?

V
 
J

JustSomeGuy

Victor said:
adding
Yes, I know of a matrix class (or two, or three). What do you mean
"add rows and columns as needed"?

Imaging a table with each row being a directory and each column being a
user name.
As I traverse the file system and find new directories i will be adding
rows to the Matrix.
As i traverse each file within the directory I will be getting the user
name of the person who
owns the file. As new owners are found a column is added to the
Matrix. Each entry in
the Matrix is a sum of the disk space used by that user.

Make sense?
 
V

Victor Bazarov

JustSomeGuy said:
Victor Bazarov wrote:




Imaging a table with each row being a directory and each column being a
user name.
As I traverse the file system and find new directories i will be adding
rows to the Matrix.
As i traverse each file within the directory I will be getting the user
name of the person who
owns the file. As new owners are found a column is added to the
Matrix. Each entry in
the Matrix is a sum of the disk space used by that user.

Make sense?

So, you essentially need an expandable table. It seems that you need some
kind of associative container that has users as keys and directories as
keys as well. The value is the "used space size". I don't think there is
one ready to use. You should roll your own. Shouldn't be that difficult.

class mytable {
std::map<std::string, int> indices_of_sizes_by_user;
std::map<std::string, int> indices_of_sizes_by_directory;
std::vector<long> sizes;
public:
void adduser(std::string const&);
void adddirectory(std::string const&);
long sumbyuser(std::string const&) const;
long sumbydirectory(std::string const&) const;
long size(std::string const& user, std::string const& dir) const;
};

Just start writing...

V
 
V

Victor Bazarov

JustSomeGuy said:
Victor Bazarov wrote:




Imaging a table with each row being a directory and each column being a
user name.
As I traverse the file system and find new directories i will be adding
rows to the Matrix.
As i traverse each file within the directory I will be getting the user
name of the person who
owns the file. As new owners are found a column is added to the
Matrix. Each entry in
the Matrix is a sum of the disk space used by that user.

Make sense?

So, you essentially need an expandable table. It seems that you need some
kind of associative container that has users as keys and directories as
keys as well. The value is the "used space size". I don't think there is
one ready to use. You should roll your own. Shouldn't be that difficult.

class mytable {
std::map<std::string, std::map<std::string,int> >
indices_of_sizes_by_user;
std::map<std::string, std::map<std::string,int> >
indices_of_sizes_by_directory;
std::vector<long> sizes;
public:
void adduser(std::string const&);
void adddirectory(std::string const&);
long sumbyuser(std::string const&) const;
long sumbydirectory(std::string const&) const;
long size(std::string const& user, std::string const& dir) const;
void addsize(std::string const& user, std::string const& dir, long);
};

The 'indices_of_sizes_by_user' contains the user name as the primary key
and the directory name as the secondary key. The value is the index of
the size of the space used by that user in that directory.

The 'indices_of_sizes_by_directory' is a symmetrical table of indices, but
now the primary key is the directory. You don't really need it, only for
sorting purposes since it is going to essentially duplicate the data in
the first one.

The 'sizes' vector is the actual storage of sizes, indexed by the values
from the map.

To make sure your 'mytable' class works correctly, remember to add to the
respective maps and to the vector every time you introduce another user or
another directory. The proposed scheme allows you not to keep zero sizes.

Just start implementing it, you'll have fun, trust me...

V
 
T

Thomas Matthews

JustSomeGuy said:
Victor Bazarov wrote:




Imaging a table with each row being a directory and each column being a
user name.
As I traverse the file system and find new directories i will be adding
rows to the Matrix.
As i traverse each file within the directory I will be getting the user
name of the person who
owns the file. As new owners are found a column is added to the
Matrix. Each entry in
the Matrix is a sum of the disk space used by that user.

Make sense?

Search the web for matrix or grid classes.


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 
A

Alf P. Steinbach

* JustSomeGuy:
Imaging a table with each row being a directory and each column being a
user name.
As I traverse the file system and find new directories i will be adding
rows to the Matrix.
As i traverse each file within the directory I will be getting the user
name of the person who
owns the file. As new owners are found a column is added to the
Matrix. Each entry in
the Matrix is a sum of the disk space used by that user.

Make sense?

Yes, but it's not a C++ question (it's off-topic in clc++).

Therefore I've cross-posted to [comp.programming] and set follow-up to
there.

The structure in your data is very classic and very simple,

username 1 <---> n sizeitem n <---> 1 directory

What you need at an abstract relational data base level:

Table Usernames row:
[usename (key), sizeitemID (ref)]

Table Directories row:
[directory (key), sizeitemID (ref)]

Table SizeItems row:
[sizeitemID (key), sizeitem, username (ref), directory (ref)]

Now go implement in C++... ;-)


XFUT: [comp.programming]
 
A

Alf P. Steinbach

* Alf P. Steinbach:
* JustSomeGuy:
Imaging a table with each row being a directory and each column being a
user name.
As I traverse the file system and find new directories i will be adding
rows to the Matrix.
As i traverse each file within the directory I will be getting the user
name of the person who
owns the file. As new owners are found a column is added to the
Matrix. Each entry in
the Matrix is a sum of the disk space used by that user.

Make sense?

Yes, but it's not a C++ question (it's off-topic in clc++).

Therefore I've cross-posted to [comp.programming] and set follow-up to
there.

The structure in your data is very classic and very simple,

username 1 <---> n sizeitem n <---> 1 directory

What you need at an abstract relational data base level:

Table Usernames row:
[usename (key), sizeitemID (ref)]

Table Directories row:
[directory (key), sizeitemID (ref)]

Table SizeItems row:
[sizeitemID (key), sizeitem, username (ref), directory (ref)]

Bah, posting in haste. Remove the sizeitemID from the first two
tables.

Now go implement in C++... ;-)

XFUT: [comp.programming]
 
J

Jonathan Turkanis

JustSomeGuy said:
Imaging a table with each row being a directory and each column being
a user name.
As I traverse the file system and find new directories i will be
adding rows to the Matrix.
As i traverse each file within the directory I will be getting the
user name of the person who
owns the file. As new owners are found a column is added to the
Matrix. Each entry in
the Matrix is a sum of the disk space used by that user.

Make sense?

Sound like the Boost.MultiIndex library might be appropriate (I can't say for
sure, since I haven't studied it):

http://www.boost.org/libs/multi_index/doc/index.html

Jonathan
 
D

Dave O'Hearn

Jonathan said:
Sound like the Boost.MultiIndex library might be appropriate (I
can't say for sure, since I haven't studied it):

http://www.boost.org/libs/multi_index/doc/index.html

I agree. I just spent a day evaluating Boost.MultiIndex, and it seems
suitable to replace an entire "relations" library I wrote a year ago,
to build many-to-many and many-to-one relations by composing sets of
sets.

I won't know for sure until I attempt replacing my library with
Boost.MultiIndex, but in general it looks great, and I recommend
keeping it in mind as an alternative anytime composing containers of
containers comes up.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,184
Messages
2,570,980
Members
47,582
Latest member
brooksmith

Latest Threads

Top