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 7440719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:53:46+00:00 2026-05-29T10:53:46+00:00

Suppose I have 3 double precision arrays a1[] , a2[] , a3[] each of

  • 0

Suppose I have 3 double precision arrays a1[], a2[], a3[] each of length L1, L2, L3

Suppose I want to concatenate these arrays “virtually” That is I want to create a virtual
array a_virtual[] such that a_virtual = {a1[L1], a2[L2], a3[L3]} logically, though physically these arrays may not be contiguous to each other.

So if I want to access a_virtual[5] and L1=2, L2=3, L3=1 then a3[0] will be fetched. For accessing a_virtual[0], a1[0] will be fetched

How would I do this

  • in C
  • in C++ (how to do this with std::vectors in place of arrays would
    also be useful)
  • in CUDA

I suspect if there is a way to do it, it would be the same for all the three environments, but there might be more efficient ways to do this within each environment depending on the
capabilities provided.

  • 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-05-29T10:53:47+00:00Added an answer on May 29, 2026 at 10:53 am

    Here’s a possible solution in C, using linked-list and (tail) recursion:

    #include <stdio.h>
    
    struct dblarr {
        double *data;
        size_t len;
        struct dblarr *next;
    };
    
    double *fetch(const struct dblarr *arr, size_t index) {
        if (arr == NULL) return NULL;
        if (index < arr->len) return arr->data + index;
        return fetch(arr->next, index - arr->len);
    }
    
    int main(void) {
        double a1[2] = {1, 2};
        double a2[3] = {1, 2, 3};
        double a3[1] = {1};
        struct dblarr x1, x2, x3;
    
        x1.data = a1; x1.len = sizeof a1 / sizeof *a1; x1.next = &x2;
        x2.data = a2; x2.len = sizeof a2 / sizeof *a2; x2.next = &x3;
        x3.data = a3; x3.len = sizeof a3 / sizeof *a3; x3.next = NULL;
    
        printf("before %f\n", *fetch(&x1, 5));
        *fetch(&x1, 5) = 0.42;
        printf(" after %f\n", *fetch(&x1, 5));
    
        return 0;
    }
    

    You can “see the code running” at http://ideone.com/mY0ix.

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

Sidebar

Related Questions

Let suppose i have 5 objects and each object contains double values. I want
I have trouble comparing 2 double in Excel VBA suppose that I have the
Suppose I have an array of class values in Java and I want to
For example suppose I have a method double roundDown(double unrounded, double precision) { }
Suppose I have a class called vector that maintains some internal, dynamic array of
Suppose that I have a string in scala and I want to try to
Suppose I have the following class: class Camera { public Camera( double exposure, double
Suppose I have a stringbuilder in C# that does this: StringBuilder sb = new
Suppose I have: Toby Tiny Tory Tily Is there an algorithm that can easily
Suppose I have BaseClass with public methods A and B, and I create DerivedClass

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.