#ifndef PARTICLE_ID_HASH
#define PARTICLE_ID_HASH
#include <maya/MPointArray.h>
class ParticleIdHash
{
private:
class ParticleSample
{
public:
ParticleSample(
int inId,
MPoint& inPosition, ParticleSample* inNext) :
id(inId), position(inPosition), next(inNext) {}
int id;
ParticleSample* next;
};
public:
ParticleIdHash(int inSize) : size(inSize) {
if (size <= 0)
{
size = 1;
}
data = new ParticleSample*[size];
for (int i = 0; i < size; i++)
{
data[i] = NULL;
}
}
~ParticleIdHash() {
for (int i = 0; i < size; i++)
{
ParticleSample* sample = data[i];
ParticleSample* prev = NULL;
while (sample != NULL)
{
prev = sample;
sample = sample->next;
delete prev;
}
}
delete [] data;
}
void insert(
int id,
MPoint& pt) {
ParticleSample* sample = new ParticleSample(id,pt,data[id%size]);
data[id%size] = sample;
}
ParticleSample* sample = data[id%size];
while (sample != NULL)
{
if (sample->id == id)
{
result.
append(sample->position);
}
sample = sample->next;
}
return result;
}
private:
ParticleSample** data;
int size;
};
#endif