问题是我有150 000多个节点,200 000+(可能有多达1 000 000甚至更多),所有节点都被写入数据库.现在我想创建一个可以打开路由访问权限的普通图表.所以,我需要使用现有数据库中的数据来组合它.我们的想法是构建这个巨大的图形,将其分成小块并写入DB BLOBS进行存储.我尝试以递归方式构建它,但在我看来,堆栈无法存储如此多的数据,并且我的算法一直打破分配错误.所以,现在我对一种允许我构建这个图的方式感到困惑.我正在考虑某种迭代方法,但主要问题是架构,我的意思是我将用于存储节点和弧的结构.当我看到这个解决方案时,应该是这样的史密斯:
struct Graph
{
unsigned int nodesAmount;
unsigned int arcsAmount;
vector<Node*> NodeArr; //Some kind of container to store all existing Nodes
}
struct Node
{
unsigned int id;
int dimension; //how many arcs use this node
vector<Arcs*> ArcArr;
}
struct Arcs
{
unsigned int id;
double cost;
Node* Node_from;
Node* Node_to;
}
Run Code Online (Sandbox Code Playgroud)
我阅读了很多关于存储图形方法的文章,但没有找到真正好的解决方案.任何想法我都会很高兴.谢谢
我已经编写了一个用于保持整数的同步队列,并面临着一种奇怪的竞争条件,我似乎无法理解.
请不要发布解决方案,我知道如何修复代码并使其工作,我想知道竞争条件是什么以及为什么它没有按预期工作.请帮助我了解出了什么问题以及原因.
首先是代码的重要部分:
这假设应用程序永远不会放入缓冲区可以容纳的数量,因此不会检查当前缓冲区大小
static inline void int_queue_put_sync(struct int_queue_s * const __restrict int_queue, const long int value ) {
if (value) { // 0 values are not allowed to be put in
size_t write_offset; // holds a current copy of the array index where to put the element
for (;;) {
// retrieve up to date write_offset copy and apply power-of-two modulus
write_offset = int_queue->write_offset & int_queue->modulus;
// if that cell currently holds 0 (thus is empty)
if …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 double * 转换为 complex* 。我只有一个 2x2 矩阵 D(双精度)的示例,我想将其转换为复数 (C):
typedef complex<double> dcmplx;
int main() {
dcmplx *C;
double *D;
int N=2;
D=new double[N*N];
C=new dcmplx[N*N];
*C=static_cast<dcmplx>(*D);
for (int i=0;i<N;i++){
for (int j=0;j<N;j++){
D[i*N+j]=i+j;
}
}
for (int i=0;i<N;i++){
for (int j=0;j<N;j++){
cout <<D[i*N+j]<<"\t";
}
cout <<"\n";
}
cout <<"\n\n";
cout <<"Complex\n";
for (int i=0;i<N;i++){
for (int j=0;j<N;j++){
cout <<C[i*N+j]<<"\t";
}
cout <<"\n";
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是正确的做法吗?
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
main()
{
int *ptr,i;
ptr=(int*)malloc(sizeof(int));
printf("sizo of ptr is:%d",sizeof(ptr));
for(i=0;i<30;i++)
scanf("%d",ptr+i);
for(i=0;i<30;i++)
printf("%d",*(ptr+i));
getch();
}
Run Code Online (Sandbox Code Playgroud)
这里ptr的大小是:4我的问题是,我想在ptr中只存储一个整数但是在这个程序中我可以存储超过30或100等,为什么它不会抛出错误?