+ return (double) tA->seconds - tB->seconds + ((double) tA->nanosec - tB->nanosec) / 1e9;
+}
+
+
+/*
+ * Allocate and copy a base event
+ *
+ * Args:
+ * newEvent: new event, pointer will be updated
+ * event: event to copy
+ */
+void copyEvent(const Event* const event, Event** const newEvent)
+{
+ g_assert(event->event.tcpEvent == NULL);
+
+ *newEvent= malloc(sizeof(Event));
+ memcpy(*newEvent, event, sizeof(Event));
+}
+
+
+/*
+ * Allocate and copy a TCP event
+ *
+ * Args:
+ * newEvent: new event, pointer will be updated
+ * event: event to copy
+ */
+void copyTCPEvent(const Event* const event, Event** const newEvent)
+{
+ g_assert(event->type == TCP);
+
+ *newEvent= malloc(sizeof(Event));
+ memcpy(*newEvent, event, sizeof(Event));
+
+ (*newEvent)->event.tcpEvent= malloc(sizeof(TCPEvent));
+ memcpy((*newEvent)->event.tcpEvent, event->event.tcpEvent,
+ sizeof(TCPEvent));
+
+ (*newEvent)->event.tcpEvent->segmentKey= malloc(sizeof(SegmentKey));
+ memcpy((*newEvent)->event.tcpEvent->segmentKey,
+ event->event.tcpEvent->segmentKey, sizeof(SegmentKey));
+}
+
+
+/*
+ * Allocate and copy a UDP event
+ *
+ * Args:
+ * newEvent: new event, pointer will be updated
+ * event: event to copy
+ */
+void copyUDPEvent(const Event* const event, Event** const newEvent)
+{
+ g_assert(event->type == UDP);
+
+ *newEvent= malloc(sizeof(Event));
+ memcpy(*newEvent, event, sizeof(Event));
+
+ (*newEvent)->event.udpEvent= malloc(sizeof(UDPEvent));
+ memcpy((*newEvent)->event.udpEvent, event->event.udpEvent,
+ sizeof(UDPEvent));
+
+ (*newEvent)->event.udpEvent->datagramKey= malloc(sizeof(DatagramKey));
+ memcpy((*newEvent)->event.udpEvent->datagramKey,
+ event->event.udpEvent->datagramKey, sizeof(DatagramKey));
+}
+
+
+/*
+ * A GFunc for g_queue_foreach()
+ *
+ * Args:
+ * data Event*, event to add
+ * user_data GArray*, array to add to
+ */
+void gfAddEventToArray(gpointer data, gpointer user_data)
+{
+ g_array_append_val((GArray*) user_data, data);