What is the most effective means to create a thin array in C+npls?

I am working with a task that calls for the adjustment of substantial matrices, especially pyramidal summation for a copula estimation.

Basically, I require to track a reasonably handful of values (generally a value of 1, and also in uncommon instances greater than 1) in a sea of absolutely nos in the matrix (multidimensional array).

A thin array permits the customer to store a handful of values, and also think all undefined documents to be a pre-programmed value. Given that it is not literally perhaps to store all values in memory, I require to store just minority non - absolutely no components. This can be numerous million access.

Rate is a massive top priority, and also I would certainly additionally such as to dynamically pick the variety of variables in the class at runtime.

I presently work with a system that makes use of a binary search tree (b - tree) to store access. Does any person recognize of a far better system?

0
2019-05-13 03:41:42
Source Share
Answers: 3

Hash tables have a rapid insertion and also seek out. You can write a straightforward hash function given that you recognize you would certainly be managing just integer sets as the keys.

0
2019-05-17 15:21:09
Source

For C+npls, a map functions well. Numerous million things will not be a trouble. 10 million things took around 4.4 secs and also concerning 57 meg on my computer system.

My examination application is as adheres to:

#include <stdio.h>
#include <stdlib.h>
#include <map>

class triple {
public:
    int x;
    int y;
    int z;
    bool operator<(const triple &other) const {
        if (x < other.x) return true;
        if (other.x < x) return false;
        if (y < other.y) return true;
        if (other.y < y) return false;
        return z < other.z;
    }
};

int main(int, char**)
{
    std::map<triple,int> data;
    triple point;
    int i;

    for (i = 0; i < 10000000; ++i) {
        point.x = rand();
        point.y = rand();
        point.z = rand();
        //printf("%d %d %d %d\n", i, point.x, point.y, point.z);
        data[point] = i;
    }
    return 0;
}

Now to dynamically pick the variety of variables, the most convenient remedy is to stand for index as a string , and afterwards make use of string as a key for the map. As an example, a thing situated at [23 ] [55 ] can be stood for using "23,55" string. We can additionally expand this remedy for greater measurements ; such as for 3 measurements an approximate index will certainly resemble "34,45,56". A straightforward execution of this strategy is as adheres to:

std::map data<string,int> data;
char ix[100];

sprintf(ix, "%d,%d", x, y); // 2 vars
data[ix] = i;

sprintf(ix, "%d,%d,%d", x, y, z); // 3 vars
data[ix] = i;
0
2019-05-17 14:37:25
Source

The ideal means to implement thin matrices is to not to implement them - atleast out your very own. I would certainly recommend to BLAS (which I assume belongs of LAPACK) which can take care of actually massive matrices.

0
2019-05-13 15:40:51
Source