- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在研究自定义数据结构,目前正在进行 Beta 测试:数据将存储在一个数组中,该数组可以表示为 4D、2D 和 1D 数组。这三个数组在 union 内声明,因为它代表相同的内存寻址。这是我类(class)的声明:
SomeClass.h
#ifndef SomeClass_H
#define SomeClass_H
class SomeClass {
public:
static const unsigned V1D_SIZE; // Single Or Linear Array Representation : Size 256 - 256 Elements
static const unsigned V2D_SIZE; // 2D Array [16][16] : Size 16 - 256 Elements
static const unsigned V4D_SIZE; // 4D Array [4][4][4][4] : Size 4 - 256 Elements
enum Index {
HEX_UNDER_FLOW = -0x01,
HEX_0 = 0x00,
HEX_1 = 0x01,
HEX_2 = 0x02,
HEX_3 = 0x03,
HEX_4 = 0x04,
HEX_5 = 0x05,
HEX_6 = 0x06,
HEX_7 = 0x07,
HEX_8 = 0x08,
HEX_9 = 0x09,
HEX_A = 0x0A,
HEX_B = 0x0B,
HEX_C = 0x0C,
HEX_D = 0x0D,
HEX_E = 0x0E,
HEX_F = 0x0F,
HEX_OVER_FLOW = 0x10
}; // Index
// Will Be Private After Testing.
union {
int m_p256[256];
int m_p16[16][16];
int m_p4[4][4][4][4];
};
private:
struct CrossReference {
Index A;
Index B;
CrossReference() {}
CrossReference( const Index& A_, const Index& B_ ) : A(A_), B(B_) {}
} typedef CR;
// Current Not Used Only Here To Illustrate A Simple Representation - May Use Or Incorporate Later
struct Cubes {
unsigned box; // 0 - 3 - w
unsigned slice; // 0 - 15 - z
unsigned row; // 0 - 15 - y
unsigned coloumn; // 0 - 15 - x
} m_cubes;
CR m_cr[256];
public:
SomeClass();
~SomeClass();
const CR& getIndexTable() const;
void displayIndexTable() const;
private:
// Must Be Called In Constructor First!
void initializeCrossReference();
}; // SomeClass
#endif // SomeClass
我需要生成此 4D 结构的坐标值对的引用查找表以实现其 1D 版本。
为了说明索引遍历,您可以引用这些图像以获得可视化表示:
注意:此图像中的 {x,y,z,w} 并不代表内存中的实际 4D 数组:它只是一种可视化!在内存中,4D 数组将如下所示:array[box][slice][row][column]
并且此图像表示 4D 数组中的 1 个框。
注意:此图像是顶部图像中描述的所有 4 个框的 2D 视觉表示。两个图像中的彩色文本对应于相应的索引。
第二张图片是此 4D 数组数据结构的二维平面网格图像表示。我们可以使用此图像生成此查找表的坐标。
此图像的每个四分之一代表 1 个框。左上角(起始)是框 0,右上角框 1,左下角框 2,右下角框 3。每个框,可以用相同的方式分解为每个切片。左上(起始)切片 0,右上切片 1,左下切片 2,右下切片 3。然后在每个切片中工作时,遍历是 row - col,一旦 col = 3,我们向下移动到下一行。因此,在完成单个切片后,我们必须根据当前切片索引跳转我们的位置。盒子也是如此。
下面是几个遍历此表以生成一组十六进制索引坐标值的示例:
array[2][3][0][1] our [A,B] hex value would be [0x0C, 0x05]
array[1][1][3][3] our [A,B] hex value would be [0x03, 0x0F]
我正在设计一个函数来生成这个查找表。我在这里手动完成了此操作:
void SomeClass::initializeCrossReference() {
//////////////////////////////////
// Upper Half Of Grid Structure //
//////////////////////////////////
// Grid Coordinates //
// Linear Or 1D Array Representation - Mapped From type[16][16] which is a
// 2D Compressed Version of type[4][4][4][4] -
// NOTE: This does not represent 4D Space; it represents a cluster of 4 (3D Cubes).
// In the declaration of the class there are two multi deminsional arrays that
// are shared in memory through a nameless union.
// ROW COL
// BOX - 0
// Slice - 0
// Row - 0 // Column Coordinates
m_cr[0].A = HEX_0; m_cr[0].B = HEX_0; // col 0
m_cr[1].A = HEX_0; m_cr[1].B = HEX_1; // col 1
m_cr[2].A = HEX_0; m_cr[2].B = HEX_2; // col 2
m_cr[3].A = HEX_0; m_cr[3].B = HEX_3; // col 3
// Row - 1
m_cr[4].A = HEX_1; m_cr[4].B = HEX_0;
m_cr[5].A = HEX_1; m_cr[5].B = HEX_1;
m_cr[6].A = HEX_1; m_cr[6].B = HEX_2;
m_cr[7].A = HEX_1; m_cr[7].B = HEX_3;
// Row - 2
m_cr[8].A = HEX_2; m_cr[8].B = HEX_0;
m_cr[9].A = HEX_2; m_cr[9].B = HEX_1;
m_cr[10].A = HEX_2; m_cr[10].B = HEX_2;
m_cr[11].A = HEX_2; m_cr[11].B = HEX_3;
// Row - 3
m_cr[12].A = HEX_3; m_cr[12].B = HEX_0;
m_cr[13].A = HEX_3; m_cr[13].B = HEX_1;
m_cr[14].A = HEX_3; m_cr[14].B = HEX_2;
m_cr[15].A = HEX_3; m_cr[15].B = HEX_3;
// Slice - 1
// Row - 0
m_cr[16].A = HEX_0; m_cr[16].B = HEX_4;
m_cr[17].A = HEX_0; m_cr[17].B = HEX_5;
m_cr[18].A = HEX_0; m_cr[18].B = HEX_6;
m_cr[19].A = HEX_0; m_cr[19].B = HEX_7;
// Row - 1
m_cr[20].A = HEX_1; m_cr[20].B = HEX_4;
m_cr[21].A = HEX_1; m_cr[21].B = HEX_5;
m_cr[22].A = HEX_1; m_cr[22].B = HEX_6;
m_cr[23].A = HEX_1; m_cr[23].B = HEX_7;
// Row - 2;
m_cr[24].A = HEX_2; m_cr[24].B = HEX_4;
m_cr[25].A = HEX_2; m_cr[25].B = HEX_5;
m_cr[26].A = HEX_2; m_cr[26].B = HEX_6;
m_cr[27].A = HEX_2; m_cr[27].B = HEX_7;
// Row - 3
m_cr[28].A = HEX_3; m_cr[28].B = HEX_4;
m_cr[29].A = HEX_3; m_cr[29].B = HEX_5;
m_cr[30].A = HEX_3; m_cr[30].B = HEX_6;
m_cr[31].A = HEX_3; m_cr[31].B = HEX_7;
// Slice - 2
// Row - 0
m_cr[32].A = HEX_4; m_cr[32].B = HEX_0;
m_cr[33].A = HEX_4; m_cr[33].B = HEX_1;
m_cr[34].A = HEX_4; m_cr[34].B = HEX_2;
m_cr[35].A = HEX_4; m_cr[35].B = HEX_3;
// Row - 1;
m_cr[36].A = HEX_5; m_cr[36].B = HEX_0;
m_cr[37].A = HEX_5; m_cr[37].B = HEX_1;
m_cr[38].A = HEX_5; m_cr[38].B = HEX_2;
m_cr[39].A = HEX_5; m_cr[39].B = HEX_3;
// Row - 2;
m_cr[40].A = HEX_6; m_cr[40].B = HEX_0;
m_cr[41].A = HEX_6; m_cr[41].B = HEX_1;
m_cr[42].A = HEX_6; m_cr[42].B = HEX_2;
m_cr[43].A = HEX_6; m_cr[43].B = HEX_3;
// Row - 3
m_cr[44].A = HEX_7; m_cr[44].B = HEX_0;
m_cr[45].A = HEX_7; m_cr[45].B = HEX_1;
m_cr[46].A = HEX_7; m_cr[46].B = HEX_2;
m_cr[47].A = HEX_7; m_cr[47].B = HEX_3;
// Slice - 3
// Row - 0
m_cr[48].A = HEX_4; m_cr[48].B = HEX_4;
m_cr[49].A = HEX_4; m_cr[49].B = HEX_5;
m_cr[50].A = HEX_4; m_cr[50].B = HEX_6;
m_cr[51].A = HEX_4; m_cr[51].B = HEX_7;
// Row - 1
m_cr[52].A = HEX_5; m_cr[52].B = HEX_4;
m_cr[53].A = HEX_5; m_cr[53].B = HEX_5;
m_cr[54].A = HEX_5; m_cr[54].B = HEX_6;
m_cr[55].A = HEX_5; m_cr[55].B = HEX_7;
// Row - 2;
m_cr[56].A = HEX_6; m_cr[56].B = HEX_4;
m_cr[57].A = HEX_6; m_cr[57].B = HEX_5;
m_cr[58].A = HEX_6; m_cr[58].B = HEX_6;
m_cr[59].A = HEX_6; m_cr[59].B = HEX_7;
// Row - 3
m_cr[60].A = HEX_7; m_cr[60].B = HEX_4;
m_cr[61].A = HEX_7; m_cr[61].B = HEX_5;
m_cr[62].A = HEX_7; m_cr[62].B = HEX_6;
m_cr[63].A = HEX_7; m_cr[63].B = HEX_7;
// BOX - 1
// Slice - 0
// Row - 0
m_cr[64].A = HEX_0; m_cr[64].B = HEX_8;
m_cr[65].A = HEX_0; m_cr[65].B = HEX_9;
m_cr[66].A = HEX_0; m_cr[66].B = HEX_A;
m_cr[67].A = HEX_0; m_cr[67].B = HEX_B;
// Row - 1
m_cr[68].A = HEX_1; m_cr[68].B = HEX_8;
m_cr[69].A = HEX_1; m_cr[69].B = HEX_9;
m_cr[70].A = HEX_1; m_cr[70].B = HEX_A;
m_cr[71].A = HEX_1; m_cr[71].B = HEX_B;
// Row - 2
m_cr[72].A = HEX_2; m_cr[72].B = HEX_8;
m_cr[73].A = HEX_2; m_cr[73].B = HEX_9;
m_cr[74].A = HEX_2; m_cr[74].B = HEX_A;
m_cr[75].A = HEX_2; m_cr[75].B = HEX_B;
// Row - 3
m_cr[76].A = HEX_3; m_cr[76].B = HEX_8;
m_cr[77].A = HEX_3; m_cr[77].B = HEX_9;
m_cr[78].A = HEX_3; m_cr[78].B = HEX_A;
m_cr[79].A = HEX_3; m_cr[79].B = HEX_B;
// Slice - 1
// Row - 0
m_cr[80].A = HEX_0; m_cr[80].B = HEX_C;
m_cr[81].A = HEX_0; m_cr[81].B = HEX_D;
m_cr[82].A = HEX_0; m_cr[82].B = HEX_E;
m_cr[83].A = HEX_0; m_cr[83].B = HEX_F;
// Row - 1
m_cr[84].A = HEX_1; m_cr[84].B = HEX_C;
m_cr[85].A = HEX_1; m_cr[85].B = HEX_D;
m_cr[86].A = HEX_1; m_cr[86].B = HEX_E;
m_cr[87].A = HEX_1; m_cr[87].B = HEX_F;
// Row - 2
m_cr[88].A = HEX_2; m_cr[88].B = HEX_C;
m_cr[89].A = HEX_2; m_cr[89].B = HEX_D;
m_cr[90].A = HEX_2; m_cr[90].B = HEX_E;
m_cr[91].A = HEX_2; m_cr[91].B = HEX_F;
// Row - 3
m_cr[92].A = HEX_3; m_cr[92].B = HEX_C;
m_cr[93].A = HEX_3; m_cr[93].B = HEX_D;
m_cr[94].A = HEX_3; m_cr[94].B = HEX_E;
m_cr[95].A = HEX_3; m_cr[95].B = HEX_F;
// Slice - 2
// Row - 0
m_cr[96].A = HEX_4; m_cr[96].B = HEX_8;
m_cr[97].A = HEX_4; m_cr[97].B = HEX_9;
m_cr[98].A = HEX_4; m_cr[98].B = HEX_A;
m_cr[99].A = HEX_4; m_cr[99].B = HEX_B;
// Row - 1
m_cr[100].A = HEX_5; m_cr[100].B = HEX_8;
m_cr[101].A = HEX_5; m_cr[101].B = HEX_9;
m_cr[102].A = HEX_5; m_cr[102].B = HEX_A;
m_cr[103].A = HEX_5; m_cr[103].B = HEX_B;
// Row - 2
m_cr[104].A = HEX_6; m_cr[104].B = HEX_8;
m_cr[105].A = HEX_6; m_cr[105].B = HEX_9;
m_cr[106].A = HEX_6; m_cr[106].B = HEX_A;
m_cr[107].A = HEX_6; m_cr[107].B = HEX_B;
// Row - 3
m_cr[108].A = HEX_7; m_cr[108].B = HEX_8;
m_cr[109].A = HEX_7; m_cr[109].B = HEX_9;
m_cr[110].A = HEX_7; m_cr[110].B = HEX_A;
m_cr[111].A = HEX_7; m_cr[111].B = HEX_B;
// Slice - 3
// Row - 0
m_cr[112].A = HEX_4; m_cr[112].B = HEX_C;
m_cr[113].A = HEX_4; m_cr[113].B = HEX_D;
m_cr[114].A = HEX_4; m_cr[114].B = HEX_E;
m_cr[115].A = HEX_4; m_cr[115].B = HEX_F;
// Row - 1
m_cr[116].A = HEX_5; m_cr[116].B = HEX_C;
m_cr[117].A = HEX_5; m_cr[117].B = HEX_D;
m_cr[118].A = HEX_5; m_cr[118].B = HEX_E;
m_cr[119].A = HEX_5; m_cr[119].B = HEX_F;
// Row - 2
m_cr[120].A = HEX_6; m_cr[120].B = HEX_C;
m_cr[121].A = HEX_6; m_cr[121].B = HEX_D;
m_cr[122].A = HEX_6; m_cr[122].B = HEX_E;
m_cr[123].A = HEX_6; m_cr[123].B = HEX_F;
// Row - 3
m_cr[124].A = HEX_7; m_cr[124].B = HEX_C;
m_cr[125].A = HEX_7; m_cr[125].B = HEX_D;
m_cr[126].A = HEX_7; m_cr[126].B = HEX_E;
m_cr[127].A = HEX_7; m_cr[127].B = HEX_F;
//////////////////////////////////
// Lower Half Of Grid Structure //
//////////////////////////////////
// Box - 2
// Slice - 0
// Row - 0
m_cr[128].A = HEX_8; m_cr[128].B = HEX_0; // col 0
m_cr[129].A = HEX_8; m_cr[129].B = HEX_1; // col 1
m_cr[130].A = HEX_8; m_cr[130].B = HEX_2; // col 2
m_cr[131].A = HEX_8; m_cr[131].B = HEX_3; // col 3
// Row - 1
m_cr[132].A = HEX_9; m_cr[132].B = HEX_0;
m_cr[133].A = HEX_9; m_cr[133].B = HEX_1;
m_cr[134].A = HEX_9; m_cr[134].B = HEX_2;
m_cr[135].A = HEX_9; m_cr[135].B = HEX_3;
// Row - 2
m_cr[136].A = HEX_A; m_cr[136].B = HEX_0;
m_cr[137].A = HEX_A; m_cr[137].B = HEX_1;
m_cr[138].A = HEX_A; m_cr[138].B = HEX_2;
m_cr[139].A = HEX_A; m_cr[139].B = HEX_3;
// Row - 3
m_cr[140].A = HEX_B; m_cr[140].B = HEX_0;
m_cr[141].A = HEX_B; m_cr[141].B = HEX_1;
m_cr[142].A = HEX_B; m_cr[142].B = HEX_2;
m_cr[143].A = HEX_B; m_cr[143].B = HEX_3;
// Slice - 1
// Row - 0
m_cr[144].A = HEX_8; m_cr[144].B = HEX_4;
m_cr[145].A = HEX_8; m_cr[145].B = HEX_5;
m_cr[146].A = HEX_8; m_cr[146].B = HEX_6;
m_cr[147].A = HEX_8; m_cr[147].B = HEX_7;
// Row - 1
m_cr[148].A = HEX_9; m_cr[148].B = HEX_4;
m_cr[149].A = HEX_9; m_cr[149].B = HEX_5;
m_cr[150].A = HEX_9; m_cr[150].B = HEX_6;
m_cr[151].A = HEX_9; m_cr[151].B = HEX_7;
// Row - 2;
m_cr[152].A = HEX_A; m_cr[152].B = HEX_4;
m_cr[153].A = HEX_A; m_cr[153].B = HEX_5;
m_cr[154].A = HEX_A; m_cr[154].B = HEX_6;
m_cr[155].A = HEX_A; m_cr[155].B = HEX_7;
// Row - 3
m_cr[156].A = HEX_B; m_cr[156].B = HEX_4;
m_cr[157].A = HEX_B; m_cr[157].B = HEX_5;
m_cr[158].A = HEX_B; m_cr[158].B = HEX_6;
m_cr[159].A = HEX_B; m_cr[159].B = HEX_7;
// Slice - 2
// Row - 0
m_cr[160].A = HEX_C; m_cr[160].B = HEX_0;
m_cr[161].A = HEX_C; m_cr[161].B = HEX_1;
m_cr[162].A = HEX_C; m_cr[162].B = HEX_2;
m_cr[163].A = HEX_C; m_cr[163].B = HEX_3;
// Row - 1;
m_cr[164].A = HEX_D; m_cr[164].B = HEX_0;
m_cr[165].A = HEX_D; m_cr[165].B = HEX_1;
m_cr[166].A = HEX_D; m_cr[166].B = HEX_2;
m_cr[167].A = HEX_D; m_cr[167].B = HEX_3;
// Row - 2;
m_cr[168].A = HEX_E; m_cr[168].B = HEX_0;
m_cr[169].A = HEX_E; m_cr[169].B = HEX_1;
m_cr[170].A = HEX_E; m_cr[170].B = HEX_2;
m_cr[171].A = HEX_E; m_cr[171].B = HEX_3;
// Row - 3
m_cr[172].A = HEX_F; m_cr[172].B = HEX_0;
m_cr[173].A = HEX_F; m_cr[173].B = HEX_1;
m_cr[174].A = HEX_F; m_cr[174].B = HEX_2;
m_cr[175].A = HEX_F; m_cr[175].B = HEX_3;
// Slice - 3
// Row - 0
m_cr[176].A = HEX_C; m_cr[176].B = HEX_4;
m_cr[177].A = HEX_C; m_cr[177].B = HEX_5;
m_cr[178].A = HEX_C; m_cr[178].B = HEX_6;
m_cr[179].A = HEX_C; m_cr[179].B = HEX_7;
// Row - 1
m_cr[180].A = HEX_D; m_cr[180].B = HEX_4;
m_cr[181].A = HEX_D; m_cr[181].B = HEX_5;
m_cr[182].A = HEX_D; m_cr[182].B = HEX_6;
m_cr[183].A = HEX_D; m_cr[183].B = HEX_7;
// Row - 2;
m_cr[184].A = HEX_E; m_cr[184].B = HEX_4;
m_cr[185].A = HEX_E; m_cr[185].B = HEX_5;
m_cr[186].A = HEX_E; m_cr[186].B = HEX_6;
m_cr[187].A = HEX_E; m_cr[187].B = HEX_7;
// Row - 3
m_cr[188].A = HEX_F; m_cr[188].B = HEX_4;
m_cr[189].A = HEX_F; m_cr[189].B = HEX_5;
m_cr[190].A = HEX_F; m_cr[190].B = HEX_6;
m_cr[191].A = HEX_F; m_cr[191].B = HEX_7;
// BOX - 3
// Slice - 0
// Row - 0
m_cr[192].A = HEX_8; m_cr[192].B = HEX_8;
m_cr[193].A = HEX_8; m_cr[193].B = HEX_9;
m_cr[194].A = HEX_8; m_cr[194].B = HEX_A;
m_cr[195].A = HEX_8; m_cr[195].B = HEX_B;
// Row - 1
m_cr[196].A = HEX_9; m_cr[196].B = HEX_8;
m_cr[197].A = HEX_9; m_cr[197].B = HEX_9;
m_cr[198].A = HEX_9; m_cr[198].B = HEX_A;
m_cr[199].A = HEX_9; m_cr[199].B = HEX_B;
// Row - 2
m_cr[200].A = HEX_A; m_cr[200].B = HEX_8;
m_cr[201].A = HEX_A; m_cr[201].B = HEX_9;
m_cr[202].A = HEX_A; m_cr[202].B = HEX_A;
m_cr[203].A = HEX_A; m_cr[203].B = HEX_B;
// Row - 3
m_cr[204].A = HEX_B; m_cr[204].B = HEX_8;
m_cr[205].A = HEX_B; m_cr[205].B = HEX_9;
m_cr[206].A = HEX_B; m_cr[206].B = HEX_A;
m_cr[207].A = HEX_B; m_cr[207].B = HEX_B;
// Slice - 1
// Row - 0
m_cr[208].A = HEX_8; m_cr[208].B = HEX_C;
m_cr[209].A = HEX_8; m_cr[209].B = HEX_D;
m_cr[210].A = HEX_8; m_cr[210].B = HEX_E;
m_cr[211].A = HEX_8; m_cr[211].B = HEX_F;
// Row - 1
m_cr[212].A = HEX_9; m_cr[212].B = HEX_C;
m_cr[213].A = HEX_9; m_cr[213].B = HEX_D;
m_cr[214].A = HEX_9; m_cr[214].B = HEX_E;
m_cr[215].A = HEX_9; m_cr[215].B = HEX_F;
// Row - 2
m_cr[216].A = HEX_A; m_cr[216].B = HEX_C;
m_cr[217].A = HEX_A; m_cr[217].B = HEX_D;
m_cr[218].A = HEX_A; m_cr[218].B = HEX_E;
m_cr[219].A = HEX_A; m_cr[219].B = HEX_F;
// Row - 3
m_cr[220].A = HEX_B; m_cr[220].B = HEX_C;
m_cr[221].A = HEX_B; m_cr[221].B = HEX_D;
m_cr[222].A = HEX_B; m_cr[222].B = HEX_E;
m_cr[223].A = HEX_B; m_cr[223].B = HEX_F;
// Slice - 2
// Row - 0
m_cr[224].A = HEX_C; m_cr[224].B = HEX_8;
m_cr[225].A = HEX_C; m_cr[225].B = HEX_9;
m_cr[226].A = HEX_C; m_cr[226].B = HEX_A;
m_cr[227].A = HEX_C; m_cr[227].B = HEX_B;
// Row - 1
m_cr[228].A = HEX_D; m_cr[228].B = HEX_8;
m_cr[229].A = HEX_D; m_cr[229].B = HEX_9;
m_cr[230].A = HEX_D; m_cr[230].B = HEX_A;
m_cr[231].A = HEX_D; m_cr[231].B = HEX_B;
// Row - 2
m_cr[232].A = HEX_E; m_cr[232].B = HEX_8;
m_cr[233].A = HEX_E; m_cr[233].B = HEX_9;
m_cr[234].A = HEX_E; m_cr[234].B = HEX_A;
m_cr[235].A = HEX_E; m_cr[235].B = HEX_B;
// Row - 3
m_cr[236].A = HEX_F; m_cr[236].B = HEX_8;
m_cr[237].A = HEX_F; m_cr[237].B = HEX_9;
m_cr[238].A = HEX_F; m_cr[238].B = HEX_A;
m_cr[239].A = HEX_F; m_cr[239].B = HEX_B;
// Slice - 3
// Row - 0
m_cr[240].A = HEX_C; m_cr[240].B = HEX_C;
m_cr[241].A = HEX_C; m_cr[241].B = HEX_D;
m_cr[242].A = HEX_C; m_cr[242].B = HEX_E;
m_cr[243].A = HEX_C; m_cr[243].B = HEX_F;
// Row - 1
m_cr[244].A = HEX_D; m_cr[244].B = HEX_C;
m_cr[245].A = HEX_D; m_cr[245].B = HEX_D;
m_cr[246].A = HEX_D; m_cr[246].B = HEX_E;
m_cr[247].A = HEX_D; m_cr[247].B = HEX_F;
// Row - 2
m_cr[248].A = HEX_E; m_cr[248].B = HEX_C;
m_cr[249].A = HEX_E; m_cr[249].B = HEX_D;
m_cr[250].A = HEX_E; m_cr[250].B = HEX_E;
m_cr[251].A = HEX_E; m_cr[251].B = HEX_F;
// Row - 3
m_cr[252].A = HEX_F; m_cr[252].B = HEX_C;
m_cr[253].A = HEX_F; m_cr[253].B = HEX_D;
m_cr[254].A = HEX_F; m_cr[254].B = HEX_E;
m_cr[255].A = HEX_F; m_cr[255].B = HEX_F;
} // initializeCrossReference
如您所见,这个函数很长,而且可读性不强。我试图找出一种以优雅的方式实现此功能的方法,这就是我被困的地方。我如何使用 for 循环和一些 if 语句(如果需要)在几行代码中生成此模式?
最终,我想将这些 [A,B] 坐标压缩成单个无符号字符,就好像 [A,B] = [0x0C,0x08] 一样,它将作为字节而不是一对枚举存储为 0xC8。
编辑 - 添加一个新图像,这应该有助于理解我如何生成我的坐标对以及它们在我的查找数组中必须处于的确切顺序。
注意:这个问题是我接受的帖子,至于旧问题在这里Custom Data Structure: Implementing an algorithim to generate a lookup table [duplicate]现在是一个死帖,请引用这个作为正确的。昨晚当我试图继续编辑旧浏览器时,我的浏览器出了问题。我本来打算删除它,但出于历史目的,我会把它留在那里,让管理部门决定是否删除它。
最佳答案
例如,像这样:
for (int i = 0; i < 256; ++i) {
int cube = i / 64;
int slice = (i % 64) / 16;
int row = (i % 16) / 4;
int col = i % 4;
m_cr[i].A = cube / 2 * 8 + slice / 2 * 4 + row;
m_cr[i].B = cube % 2 * 8 + slice % 2 * 4 + col;
}
关于c++ - 实现查找表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36416290/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!