Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ctime>
- #include <iostream>
- typedef float pnt[3];
- void count(pnt* pnts, const int n, unsigned cnt[8]) {
- for (int i = 0; i < 8; ++i)
- cnt[i] = 0;
- for (int i = 0; i < n; ++i) {
- int index = 0;
- int x = -((int)pnts[i][0]) & (1 << 31);
- x = abs(x >> 31);
- index += x;
- int y = -((int)pnts[i][1]) & (1 << 31);
- y = abs(y >> 31);
- index += (y * 2);
- int z = -((int)pnts[i][2]) & (1 << 31);
- z = abs(z >> 31);
- index += (z * 4);
- ++cnt[index];
- }
- for (int i = 0; i < 8; ++i)
- std::cout << cnt[i] << std::endl;
- }
- void counting(pnt* pnts, const int n, unsigned cnt[8]) {
- for (int i = 0; i < 8; ++i)
- cnt[i] = 0;
- for (int i = 0; i < n; ++i) {
- if (pnts[i][0] >= 0.0f && pnts[i][1] >= 0.0f && pnts[i][2] >= 0.0f) ++cnt[7]; else
- if (pnts[i][0] >= 0.0f && pnts[i][1] >= 0.0f && pnts[i][2] < 0.0f) ++cnt[3]; else
- if (pnts[i][0] >= 0.0f && pnts[i][1] < 0.0f && pnts[i][2] >= 0.0f) ++cnt[5]; else
- if (pnts[i][0] >= 0.0f && pnts[i][1] < 0.0f && pnts[i][2] < 0.0f) ++cnt[1]; else
- if (pnts[i][0] < 0.0f && pnts[i][1] >= 0.0f && pnts[i][2] >= 0.0f) ++cnt[6]; else
- if (pnts[i][0] < 0.0f && pnts[i][1] >= 0.0f && pnts[i][2] < 0.0f) ++cnt[2]; else
- if (pnts[i][0] < 0.0f && pnts[i][1] < 0.0f && pnts[i][2] >= 0.0f) ++cnt[4]; else
- ++cnt[0];
- }
- for (int i = 0; i < 8; ++i)
- std::cout << cnt[i] << std::endl;
- }
- int main() {
- srand((unsigned)time(0));
- pnt* points = new pnt[16777216];
- for (int i = 0; i < 16777216; i++) {
- points[i][0] = (-100 +(float)rand() / (float)(RAND_MAX / (100 - -100)));
- points[i][1] = (-100 + (float)rand() / (float)(RAND_MAX / (100 - -100)));
- points[i][2] = (-100 + (float)rand() / (float)(RAND_MAX / (100 - -100)));
- }
- unsigned int y[8];
- count(points, 16777216, y);
- delete [] points;
- std::cout << clock();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement