Perform factor reduction as a modular step
[lttv.git] / lttv / lttv / sync / data_structures.c
index c2bf6467227de36a36c7cbc0a8500f251d4ae458..79b8963d61427d83b48a2feebb2051c471a2322b 100644 (file)
 #define SEQ_GT(a,b)     ((int32_t)((a)-(b)) > 0)
 #define SEQ_GEQ(a,b)    ((int32_t)((a)-(b)) >= 0)
 
+const char* const approxNames[]= {
+       [EXACT]= "Exact",
+       [ACCURATE]= "Accurate",
+       [APPROXIMATE]= "Approximate",
+       [INCOMPLETE]= "Incomplete",
+       [ABSENT]= "Absent",
+       [SCREWED]= "Screwed",
+};
+
 
 /*
  * Compare two ConnectionKey structures
@@ -453,9 +462,14 @@ void gdnConnectionKeyDestroy(gpointer data)
 guint ghfDatagramKeyHash(gconstpointer key)
 {
        DatagramKey* datagramKey;
+       union {
+               uint8_t byteKey[8];
+               uint32_t hashableKey[2];
+       } dataKey;
        uint32_t a, b, c;
 
        datagramKey= (DatagramKey*) key;
+       memcpy(dataKey.byteKey, datagramKey->dataKey, sizeof(dataKey.byteKey));
 
        a= datagramKey->saddr;
        b= datagramKey->daddr;
@@ -463,8 +477,8 @@ guint ghfDatagramKeyHash(gconstpointer key)
        mix(a, b, c);
 
        a+= datagramKey->ulen; // 16 bits left here
-       b+= *((uint32_t*) datagramKey->dataKey);
-       c+= *((uint32_t*) ((void*) datagramKey->dataKey + 4));
+       b+= dataKey.hashableKey[0];
+       c+= dataKey.hashableKey[1];
        final(a, b, c);
 
        return c;
@@ -644,3 +658,98 @@ void gfAddEventToArray(gpointer data, gpointer user_data)
 {
        g_array_append_val((GArray*) user_data, data);
 }
+
+
+/*
+ * Free a PairFactors
+ *
+ * Args:
+ *   factorsCHull: container of Factors
+ */
+void destroyPairFactors(PairFactors* pairFactors)
+{
+       if (pairFactors->min != NULL)
+       {
+               free(pairFactors->min);
+       }
+       if (pairFactors->max != NULL)
+       {
+               free(pairFactors->max);
+       }
+       if (pairFactors->approx != NULL)
+       {
+               free(pairFactors->approx);
+       }
+}
+
+
+/*
+ * Create and initialize a container of PairFactors
+ *
+ * Args:
+ *   traceNb:      number of traces
+ *
+ * Returns:
+ *   A new array, which can be freed with freeAllFactors()
+ */
+AllFactors* createAllFactors(const unsigned int traceNb)
+{
+       AllFactors* allFactors;
+       PairFactors** factorsArray;
+       unsigned int i, j;
+
+       allFactors= malloc(sizeof(AllFactors));
+       allFactors->refCount= 1;
+       allFactors->pairFactors= malloc(traceNb * sizeof(PairFactors*));
+       factorsArray=allFactors->pairFactors;
+       for (i= 0; i < traceNb; i++)
+       {
+               factorsArray[i]= calloc(traceNb, sizeof(PairFactors));
+
+               for (j= 0; j < traceNb; j++)
+               {
+                       if (i == j)
+                       {
+                               factorsArray[i][i].type= EXACT;
+                               factorsArray[i][i].approx= malloc(sizeof(Factors));
+                               factorsArray[i][i].approx->drift= 1.;
+                               factorsArray[i][i].approx->offset= 0.;
+                       }
+                       else
+                       {
+                               factorsArray[i][j].type= ABSENT;
+                       }
+               }
+       }
+
+       return allFactors;
+}
+
+
+/*
+ * Free a container of PairFactors
+ *
+ * Args:
+ *   allFactors:   container of PairFactors
+ *   traceNb:      number of traces
+ */
+void freeAllFactors(AllFactors* const allFactors, const unsigned int traceNb)
+{
+       unsigned int i, j;
+
+       allFactors->refCount--;
+
+       if (allFactors->refCount == 0)
+       {
+               for (i= 0; i < traceNb; i++)
+               {
+                       for (j= 0; j < traceNb; j++)
+                       {
+                               destroyPairFactors(&allFactors->pairFactors[i][j]);
+                       }
+                       free(allFactors->pairFactors[i]);
+               }
+               free(allFactors->pairFactors);
+               free(allFactors);
+       }
+}
This page took 0.025936 seconds and 4 git commands to generate.