Looking for a C++ class.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JustSomeGuy

    Looking for a C++ class.

    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?



  • Victor Bazarov

    #2
    Re: Looking for a C++ class.

    JustSomeGuy wrote:[color=blue]
    > 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?[/color]

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

    V

    Comment

    • JustSomeGuy

      #3
      Re: Looking for a C++ class.

      Victor Bazarov wrote:
      [color=blue]
      > JustSomeGuy wrote:[color=green]
      > > 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?[/color]
      > adding
      > Yes, I know of a matrix class (or two, or three). What do you mean
      > "add rows and columns as needed"?[/color]

      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?



      Comment

      • Victor Bazarov

        #4
        Re: Looking for a C++ class.

        JustSomeGuy wrote:[color=blue]
        > Victor Bazarov wrote:
        >
        >[color=green]
        >>JustSomeGuy wrote:
        >>[color=darkred]
        >>>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?[/color]
        >>
        >>adding
        >>Yes, I know of a matrix class (or two, or three). What do you mean
        >>"add rows and columns as needed"?[/color]
        >
        >
        > 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?[/color]

        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::s tring, int> indices_of_size s_by_user;
        std::map<std::s tring, int> indices_of_size s_by_directory;
        std::vector<lon g> sizes;
        public:
        void adduser(std::st ring const&);
        void adddirectory(st d::string const&);
        long sumbyuser(std:: string const&) const;
        long sumbydirectory( std::string const&) const;
        long size(std::strin g const& user, std::string const& dir) const;
        };

        Just start writing...

        V

        Comment

        • Victor Bazarov

          #5
          Re: Looking for a C++ class.

          JustSomeGuy wrote:[color=blue]
          > Victor Bazarov wrote:
          >
          >[color=green]
          >>JustSomeGuy wrote:
          >>[color=darkred]
          >>>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?[/color]
          >>
          >>adding
          >>Yes, I know of a matrix class (or two, or three). What do you mean
          >>"add rows and columns as needed"?[/color]
          >
          >
          > 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?[/color]

          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::s tring, std::map<std::s tring,int> >
          indices_of_size s_by_user;
          std::map<std::s tring, std::map<std::s tring,int> >
          indices_of_size s_by_directory;
          std::vector<lon g> sizes;
          public:
          void adduser(std::st ring const&);
          void adddirectory(st d::string const&);
          long sumbyuser(std:: string const&) const;
          long sumbydirectory( std::string const&) const;
          long size(std::strin g const& user, std::string const& dir) const;
          void addsize(std::st ring const& user, std::string const& dir, long);
          };

          The 'indices_of_siz es_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_siz es_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[s].

          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

          Comment

          • Thomas Matthews

            #6
            Re: Looking for a C++ class.

            JustSomeGuy wrote:[color=blue]
            > Victor Bazarov wrote:
            >
            >[color=green]
            >>JustSomeGuy wrote:
            >>[color=darkred]
            >>>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?[/color]
            >>
            >>adding
            >>Yes, I know of a matrix class (or two, or three). What do you mean
            >>"add rows and columns as needed"?[/color]
            >
            >
            > 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?
            >
            >
            >[/color]

            Search the web for matrix or grid classes.


            --
            Thomas Matthews

            C++ newsgroup welcome message:

            C++ Faq: http://www.parashift.com/c++-faq-lite
            C Faq: http://www.eskimo.com/~scs/c-faq/top.html
            alt.comp.lang.l earn.c-c++ faq:

            Other sites:
            http://www.josuttis.com -- C++ STL Library book
            http://www.sgi.com/tech/stl -- Standard Template Library

            Comment

            • Alf P. Steinbach

              #7
              Re: Looking for a C++ class.

              * JustSomeGuy:[color=blue]
              >
              > 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?[/color]

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

              Therefore I've cross-posted to [comp.programmin g] 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.programmin g]

              --
              A: Because it messes up the order in which people normally read text.
              Q: Why is it such a bad thing?
              A: Top-posting.
              Q: What is the most annoying thing on usenet and in e-mail?

              Comment

              • Alf P. Steinbach

                #8
                Re: Looking for a C++ class.

                * Alf P. Steinbach:[color=blue]
                > * JustSomeGuy:[color=green]
                > >
                > > 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?[/color]
                >
                > Yes, but it's not a C++ question (it's off-topic in clc++).
                >
                > Therefore I've cross-posted to [comp.programmin g] 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)][/color]

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

                [color=blue]
                > Now go implement in C++... ;-)
                >
                > XFUT: [comp.programmin g][/color]

                --
                A: Because it messes up the order in which people normally read text.
                Q: Why is it such a bad thing?
                A: Top-posting.
                Q: What is the most annoying thing on usenet and in e-mail?

                Comment

                • Jonathan Turkanis

                  #9
                  Re: Looking for a C++ class.

                  JustSomeGuy wrote:
                  [color=blue]
                  > 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?[/color]

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



                  Jonathan


                  Comment

                  • Dave O'Hearn

                    #10
                    Re: Looking for a C++ class.

                    Jonathan Turkanis wrote:[color=blue]
                    > Sound like the Boost.MultiInde x 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[/color]

                    I agree. I just spent a day evaluating Boost.MultiInde x, 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.MultiInde x, but in general it looks great, and I recommend
                    keeping it in mind as an alternative anytime composing containers of
                    containers comes up.

                    --
                    Dave O'Hearn

                    Comment

                    Working...