Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8141663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:35:13+00:00 2026-06-06T12:35:13+00:00

I am representing map ( matrix rows x columns ) with bits using bitset

  • 0

I am representing map ( matrix rows x columns ) with bits using bitset from stl or dynamic_bitset<> from boost ( I can use whatever I want ). I need to get submatrix of that matrix with smaller size( for example
a(2,2) a(2,3) a(3,2) a(3,3) there is size 2 ). Is there any efficient structure for representing matrix with bits and getting submatrix from startindex and length without iteration ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:35:15+00:00Added an answer on June 6, 2026 at 12:35 pm

    It is possible to efficiently share data between matrices and submatrices. The trick is to track three variables in your class.

    • row_stride
    • start
    • data

    The data needs to be a shared_ptr like structure so that the underlying data can be destroyed once you are done with it. start will be a pointer into the data referenced by data, row_stride tells you how far to move to get to the next row.

    Additional things you might like to track are

    • column stride (This can allow you to take other interesting views into the matrix, and to support transpose efficiently).
    • row and column length – these can be handy for debugging or if you want to make your loops, and multiplies easier to work with.

    Here’s how this might look for a non-bit based approach (I’ve omitted much .. but hopefully you get the gist).

    template<typename T>
    struct MatrixData
    {
       T * data;
       explicit MatrixData( size_t N ) { new T[N]; }
       ~MatrixData() { delete [] data; }
    private:
        MatrixData( const MatrixData & );
        MatrixData& operator=( const MatrixData & );
    };
    
    template<typename T>
    class Matrix
    {
        Matrix(size_t nni, size_t nnj) :
          data( new MatrixData( nni*nnj ) ),
          ni(nni),
          nj(nnj),
          row_stride(ni),
          col_stride(1)
        {
        }
    
        T operator()( size_t i, size_t j)
        {
           assert( i < ni );
           assert( j < nj );
           return start + i * col_stride + j * row_stride;
        }
    
        Matrix submatrix( size_t i_start, size_t j_start, size_t new_ni, size_t new_nj )
        {
           assert( i_start + new_ni < ni );
           assert( j_start + new_nj < nj );
    
           Matrix retval(*this);
           retval.start += i_start * col_stride + j_start * row_stride;
           retval.ni = new_ni;
           retval.nj = new_nj;
           return retval;
        }
    
        Matrix transpose()
        {
           Matrix retval(*this);
           std::swap(retval.ni,retval.nj);
           std::swap(retval.row_stride,retval.col_stride);
        }
    
      private:
        shared_ptr<MatrixData> data;
        T* start;
        size_t ni;
        size_t nj;
        size_t row_stride;
        size_t col_stride;
    
    };
    

    Making this work for a bit based version would mean changing the MatrixData to hold one of the bot based structures, changing start to be an index into the structure and changing your operator() to access the data correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Rendering a 3D-map from an Openstreetmap data can be pretty cumbersome . But what
I have two maps of type Map<Long, Integer>, one named oldValues representing the old
For representing a length or count variable, is it better to use signed or
I have a series of classes representing smart map elements: MapTextElement , MapIconElement ,
I've got an MKAnnotation subclass representing a cluster of map pins, with the number
I have a map, where string representing the name of attribute and the second
I have a strange problem with a calculator made using boost::spirit. This calculator is
I want to convert from char representing a hexadecimal value (in upper or lower
I am trying to produce a heat map using ggplot2. I found this example
I have a collection in my database representing IP addresses pulled from various sources.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.