/*----------------------------------------------- * * Associative LMS vector search (Host) * */ #include #include "lms.h" #define MAXINT (0x7fffffff) #define SQR(x) ((x)*(x)) #define EOL (-1) typedef short unsigned int datatype; datatype data[RECORDS][VECTORSIZE]; void updateBest(datatype key[VECTORSIZE], datatype newdata[VECTORSIZE]) { int r, v; int error, besterror; int tail, previousBest[RECORDS]; /* find record(s) with best LMS fit */ besterror = MAXINT; for (r = 0; r < RECORDS; r++) { error = 0; for (v = 0; v < VECTORSIZE; v++) error += SQR((data[r][v]) - key[v]); if (error < besterror) { besterror = error; previousBest[r] = EOL; tail = r; } else if (error == besterror) { previousBest[r] = tail; tail = r; } } /* replace record(s) with best LMS fit */ r = tail; do { /* update record with new value */ for (v = 0; v < VECTORSIZE; v++) data[r][v] = newdata[v]; r = previousBest[r]; } while (r != EOL); }