-
Notifications
You must be signed in to change notification settings - Fork 0
/
gridhash.h
62 lines (47 loc) · 844 Bytes
/
gridhash.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef GRID_HASH_HEADER
#define GRID_HASH_HEADER
#include <inttypes.h>
#include "boid.h"
#include "dmath.h"
class Lock;
class GridHash;
class HashNode
{
friend class GridHash;
private:
HashNode *next;
UIntVec pos;
public:
HashNode()
{
}
void init(const UIntVec &newPos)
{
next = nullptr;
pos = newPos;
boids = nullptr;
}
Boid *boids;
};
class GridHash
{
private:
Vec min;
Vec max;
Vec size;
real cellSize;
real cellSizeInv;
HashNode **hashArray;
Lock *hashLocks;
uintptr_t hashSize;
HashNode* getNewNode(const UIntVec &newPos);
void freeNode(HashNode *node);
public:
GridHash();
~GridHash();
void setDims(const Vec &min, const Vec &max, real searchDist,
uintptr_t hashSize);
void add(Boid *boid);
void getNodes(const Boid *boid, HashNode *outNodes[]) const;
};
#endif /* GRID_HASH_HEADER */