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