Thread: Pre-Mapping issue (could be in C or C++ )

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2020
    Posts
    34

    Pre-Mapping issue (could be in C or C++ )

    I'm trying to implement a function in C++(or c) that gets two inputs, one input is an array of integers value (binary values just zero or one) , the second input is an integer value one of those values: 1 , 2, 4, 8.
    the function returns the correct pre-mapped pattern according to this table:
    Pre-Mapping issue (could be in C or C++ )-news-jpg

    I mean by pre-mapped pattern, a pattern that it was before mapping it according to the table !.
    to elaborate more, I'm giving examples: (Remap is the name of the function, we always read the given input array from left to right ..)
    Code:
    Ramp(given array, DSSS value) - the function format.
    
    first example: Remap({0,1} , 1 ) => returns an integer array according to the table {0, 1};
     (we see that 0 is mapped to value 0 , 1 is mapped to value 0 if the multiply=1)
    
    second example: Remap({1 ,1 , 0 , 0} , 2 ) => returns an integer array according to the table {1 ,0}; (we see that 11 is mapped to value 1 , 00 is mapped to value 0 if the multiply=2, so the output is {1,0})
    
    third example: Remap({1 ,1 , 0 , 0 , 0 , 0 , 1 , 1} , 4 ) => returns an integer array according to the table {0 ,1}; (we see that 1100 is mapped to value 0 , 0011 is mapped to value 1 if the multiply=4 so output is {0,1})
    
    third example: Remap({1 ,1 , 0 , 0 , 1 , 1, 0 , 0} , 8) => returns an integer array according to the table {0}; (we see that 11001100 is mapped to value 0 if the multiply=8 so output is {0} )
    
    the given array is always in its rules according to the table, this means there's no case like the patterns in the given array aren't the same as the patterns on the table, for instance this array {001} with multiply 2 isn't possible .. !
    
    In brief we are returning the pre-mapped pattern according to the attached table of mapping. (the attached table is given by default in the question itself) 
    


    My implementation code C++ is:

    Code:
    
    
    Code:
    #include <iostream>
    #include <vector>
    std::vector<int> Remap(int* givenArray, int DSSS)
    {
        std::vector<int> ret;                                                      // result's utput
        switch (multiply) {
            case 1:    {
                int l[2] = { 0,1 };                                               // for first opition in the table
                for (int i = 0; i < 2; i++)
                    ret.push_back(l[i]);
            }
            break;
            case 2:    {
                int l[4] = { 0 ,0 ,1 ,1 };                                           //for second opition in the table
                for (int i = 0; i < 4; i++)
                    ret.push_back(l[i]);
            }
            break;
            case 4:    {
                int l[8] = { 0 ,0,1 ,1 ,1 ,1 ,0 ,0 };                                  // for third opition in the table
                for (int i = 0; i < 8; i++)
                    ret.push_back(l[i]);
            }
                break;
            case 8: {
                int l[16] = { 0 ,0,1,1,1,1,0,0 ,1,1,0,0,0,0,1,1 };                // for fourth opition in the table
                for (int i = 0; i < 16; i++)
                    ret.push_back(l[i]);
            }
            break;
        }
        return ret; // returning the correspond pre-mapped array according to given DSSS value to the function main 
    }
    
    
    int main()
    {
        int MappedPattern[4] = { 0,0,1,1 };
        std::vector<int> PremappedPattern = Remap(MappedPattern, 2); // it should return {0,1} because 00 -> 0 , 
         //11->1 according to the table over multiply =2
            return 0;
    }
    ````
    What's wrong with my code? any help please in my implementation for the problem? honestly Im stuck on this, so it would be appreciated if there's any assistance to solve my problem or any other algorithms suggestions for my problem!
    I was thinking to use hashtable but I don't know if it's efficient or not.
    THANKS ALOT.
    Last edited by JohnnyOmari; 12-31-2020 at 03:16 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. mapping in C++
    By jack_carver in forum C++ Programming
    Replies: 5
    Last Post: 04-17-2009, 10:00 AM
  2. help using strings and mapping
    By trprince in forum C Programming
    Replies: 29
    Last Post: 12-01-2007, 04:01 PM
  3. username to uid mapping
    By rotis23 in forum C Programming
    Replies: 1
    Last Post: 10-30-2002, 04:17 AM
  4. Mapping
    By Scorpion-ice in forum Game Programming
    Replies: 0
    Last Post: 07-02-2002, 01:32 PM

Tags for this Thread