-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTemporalNodeInterval.cpp
More file actions
56 lines (48 loc) · 1.39 KB
/
TemporalNodeInterval.cpp
File metadata and controls
56 lines (48 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <vector>
#include <iostream>
#include <stdlib.h>
#include "TemporalNode.h"
#include "IntervalTree.h"
TemporalNode::TemporalNode(int isNodeId){
nodeId = isNodeId;
t = new IntervalTree();
}
void TemporalNode::addEdge(int destId, int startTime, bool direction){
if (direction){
fwdEdges.push_back(new TemporalEdge(destId, startTime));
Interval *i = new Interval(startTime);
t->add(destId, i);
}
//else do nothing (IntervalTree approach does not require reverse edges
}
int TemporalNode::removeEdge(int destId, int endTime, bool direction){
int startTime = -1;
if (direction){
for (int i = 0; i < fwdEdges.size(); i++){
if ((fwdEdges[i]->getDestId() == destId) && (fwdEdges[i]->getEndTime() == -1)){
fwdEdges[i]->setEndTime(endTime);
startTime = fwdEdges[i]->getStartTime();
break;
}
}
if (startTime == -1) return -1;
Interval *i = new Interval(startTime, -1);
IntervalNode *n = t->findInterval(t->root, destId, i);
t->removeNode(n);
free(i);
i = new Interval(startTime, endTime);
t->add(destId, i);
}
return startTime;
}
int TemporalNode::getNumEdges(bool direction){
return fwdEdges.size();
}
TemporalEdge* TemporalNode::getEdgeAt(int i, bool direction){
return fwdEdges[i];
}
vector<IntervalNode*> TemporalNode::getOverlappingEdges(Interval *x, bool direction){
vector<IntervalNode*> foundIntervals;
t->search(x, foundIntervals);
return foundIntervals;
}