const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]);
const float max_load_factor = 0.65;
+#define BAD_RECORD (0xc693748)
+
/*****************************************************************************/
struct hashtable *
create_hashtable(unsigned int minsize,
}
/*****************************************************************************/
+int entered = 0;
+
int
hashtable_insert(struct hashtable *h, void *k, void *v)
{
* element may be ok. Next time we insert, we'll try expanding again.*/
hashtable_expand(h);
}
+ if (entered) {
+ struct entry* eTest = (struct entry*)BAD_RECORD;
+ if (eTest->v == (void*)0x3f800000) {
+ //printf("Insert CORRUPT\n");
+ }
+ }
e = (struct entry *)malloc(sizeof(struct entry));
if (NULL == e) { --(h->entrycount); return 0; } /*oom*/
+ if (e == (void*)BAD_RECORD) {
+ entered = 1;
+ //printf("Allocated 0x%x\n", e);
+ }
e->h = hash(h,k);
+ if (e->h == 4101970376) {
+ int i;
+ //printf("Inserting key with suspect hashvalue:\n ");
+ for (i = 0; i < 20; i++) {
+ //printf("%hhi ", ((char*)k)[i]);
+ }
+ //printf("\n");
+ }
tindex = indexFor(h->tablelength,e->h);
- if (v == (void*)0x477fed00) {
- printf("CORRUPT\n");
+ if (v == (void*)0x3f800000) {
+ //printf("Insert post CORRUPT\n");
}
e->k = k;
e->v = v;
hashvalue = hash(h,k);
tindex = indexFor(h->tablelength,hashvalue);
e = h->table[tindex];
- if (hashvalue == 1741511095) {
- int i = 5;
+ if (entered) {
+ struct entry* eTest = (struct entry*)BAD_RECORD;
+ if (eTest->v == (void*)0x3f800000) {
+ //printf("Search CORRUPT\n");
+ }
}
while (NULL != e)
{
/* Check hash value to short circuit heavier comparison */
if ((hashvalue == e->h) && (h->eqfn(k, e->k))) {
- if ((int)e->v == 0x477fed00) {
- printf("ALARM\n");
+ if (hashvalue == 4101970376) {
+ //printf("Retreiving key with suspect hhashvalue: 0x%x -> 0x%x\n", e, e->v);
+ }
+ if ((int)e->v == 0x3f800000) {
+ //printf("ALARM: 0x%x has 0x%x\n", e, e->v);
}
return e->v;
}
*/
/* Globals */
-static double u[97],c,cd,cm;
+static double randU[97], randC, randCD, randCM;
static int i97,j97;
static int test = FALSE;
s += t;
t *= 0.5;
}
- u[ii] = s;
+ randU[ii] = s;
}
- c = 362436.0 / 16777216.0;
- cd = 7654321.0 / 16777216.0;
- cm = 16777213.0 / 16777216.0;
+ randC = 362436.0 / 16777216.0;
+ randCD = 7654321.0 / 16777216.0;
+ randCM = 16777213.0 / 16777216.0;
i97 = 97;
j97 = 33;
test = TRUE;
RandomInitialise(seed1,seed2);
#endif
}
- uni = u[i97-1] - u[j97-1];
+ uni = randU[i97-1] - randU[j97-1];
if (uni <= 0.0)
uni++;
- u[i97-1] = uni;
+ randU[i97-1] = uni;
i97--;
if (i97 == 0)
i97 = 97;
j97--;
if (j97 == 0)
j97 = 97;
- c -= cd;
- if (c < 0.0)
- c += cm;
- uni -= c;
+ randC -= randCD;
+ if (randC < 0.0)
+ randC += randCM;
+ uni -= randC;
if (uni < 0.0)
uni++;
uint8_t search_bin_num(char noise)__attribute__ ((C, spontaneous))
{
uint8_t bin;
+ if (noise > NOISE_MAX || noise < NOISE_MIN) {
+ noise = NOISE_MIN;
+ }
bin = (noise-NOISE_MIN)/NOISE_QUANTIZE_INTERVAL + 1;
return bin;
}
sim_noise_dist(node_id);
arrangeKey(node_id);
for(i = NOISE_HISTORY; i < noiseData[node_id].noiseTraceIndex; i++) {
+ if (i >= 196605) {
+ int foo = 7;
+ }
if (i == NOISE_HISTORY) {
printf("Inserting first element.\n");
}
prev_t = noiseData[node_id].noiseGenTime;
+ if (noiseData[node_id].generated == 0) {
+ dbgerror("TOSSIM", "Tried to generate noise from an uninitialized radio model of node %hu.\n", node_id);
+ return 127;
+ }
+
if ( (0<= cur_t) && (cur_t < NOISE_HISTORY) ) {
noiseData[node_id].noiseGenTime = cur_t;
noiseData[node_id].key[cur_t] = search_bin_num(noiseData[node_id].noiseTrace[cur_t]);
sim_noise_add(node_id, noiseData[node_id].noiseTrace[i+1]);
arrangeKey(node_id);
}
+ noiseData[node_id].generated = 1;
}