#include <math.h>
#include <queue>
#include <hboost/functional/hash.hpp>
#include <stdlib.h>
namespace HDK_Sample {
static double
frandom(std::size_t 
hash)
{
#if 1
    
    
    
    uint        seed = hash & (0xffffffff);
 
    return SYSfastRandom(seed);
#else
    srandom(hash);
    return double(random()) * (1.0/RAND_MAX);
#endif
}
static double
hash(int ix, int iy, int iz)
{
    std::size_t hash = 0;
    hboost::hash_combine(hash, ix);
    hboost::hash_combine(hash, iy);
    hboost::hash_combine(hash, iz);
    return frandom(hash);
}
static double hash_1(int ix, int iy, int iz) { return hash(ix, iy, iz); }
static double hash_2(int ix, int iy, int iz) { return hash(iy, iz, ix); }
static double hash_3(int ix, int iy, int iz) { return hash(iz, ix, iy); }
static double hash_4(int ix, int iy, int iz) { return hash(ix, iz, iy); }
static double
rbf(double d)
{
    
    auto smooth = [](
double d) { 
return d*d*(3 - 2*d); };
 
    return d < 1 ? 
smooth(1-d) : 0;
 
}
static void
getCenter(int ix, int iy, int iz, const int ipos[3], double center[3])
{
    
    
    
    center[0] = hash_1(ix+ipos[0], iy+ipos[1], iz+ipos[2]) + ix;
    center[1] = hash_2(ix+ipos[0], iy+ipos[1], iz+ipos[2]) + iy;
    center[2] = hash_3(ix+ipos[0], iy+ipos[1], iz+ipos[2]) + iz;
}
double
noiseValue(int ix, int iy, int iz, const int ipos[3])
{
    return hash_4(ix+ipos[0], iy+ipos[1], iz+ipos[2]);
}
static double
distance(
const double *p0, 
const double *p1)
 
{
    
    double      sum = 0;
    for (int i = 0; i < 3; ++i)
        sum += (p0[i]-p1[i]) * (p0[i]-p1[i]);
    return SYSsqrt(sum);
}
static double
alligator(const double pos[3])
{
    int                         ipos[3]; 
    double                      fpos[3]; 
    double                      vpos[3]; 
    int                         idx = 0;
    std::priority_queue<double> nvals;
    for (int i = 0; i < 3; ++i)
    {
        fpos[i] = pos[i] - ipos[i];
    }
    for (int ix = -1; ix <= 1; ++ix)
    {
        for (int iy = -1; iy <= 1; ++iy)
        {
            for (int iz = -1; iz <= 1; ++iz, ++idx)
            {
                getCenter(ix, iy, iz, ipos, vpos);
                if (d < 1)
                {
                    
                    double      v = noiseValue(ix, iy, iz, ipos) * rbf(d);
 
                    nvals.push(v);
                }
            }
        }
    }
    if (!nvals.size())
        return 0;
    double max = nvals.top();
 
    nvals.pop();
    if (nvals.size())
        max -= nvals.top();
}
static void
alligator_Evaluate(int, void *argv[], void *)
{
    auto result = (
float *)argv[0];
 
    auto fpos = ((
const UT_Vector3 *)argv[1])->data();
 
    double      pos[3];
}
}
using namespace HDK_Sample;
void
{
                    alligator_Evaluate,
                    nullptr,
                    nullptr);
}