-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtestSketch.py
executable file
·66 lines (53 loc) · 1.88 KB
/
testSketch.py
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
57
58
59
60
61
62
63
64
65
66
class SrcDest(object):
def __init__(self, srcAddr,DestSet):
self.DestSet = DestSet
self.srcAddr = srcAddr
self.match = self
def __eq__(self, other):
result = (self.srcAddr == other.srcAddr)
if result:
self.match = other
other.DestSet = self.DestSet | other.DestSet
#print "Match: new self length" + str(len(other.DestSet))
#print "updateSet: new " + str(other.DestSet)
return result
def __ne__(self, other):
return self.srcAddr != other.srcAddr
def __hash__(self):
return hash(self.srcAddr)
from sets import Set
import sys
if __name__ == '__main__':
entireSet = Set()
f = sys.argv[1]
with open(f, 'r') as fin:
counter = 0
for line in fin:
counter += 1
if (counter % 100000) == 0:
sys.stderr.write(str(counter//100000) + "%\n")
arr = line.strip().split(',') # [src, dst]
dest1 = Set([arr[1]])
sd1 = SrcDest(arr[0],dest1)
if sd1 in entireSet:
#print "--------Main Loop--------"
#print "existing " + str(sd1.DestSet)
#print "new " + str(dest1)
#print "Updated length " + str(len(sd1.DestSet))
#print "------End Main Loop------"
entireSet.discard(sd1)
entireSet.add(sd1)
#print sd1.match.DestSet
else:
entireSet.add(sd1)
k = sys.argv[2]
printDestNum = sys.argv[3]
for src in entireSet:
#print src.srcAddr + " " + str(len(src.DestSet))
#for dst in src.DestSet:
# print dst + ","
if len(src.DestSet) >= int(k):
if int(printDestNum) == 1:
print src.srcAddr + " " + str(len(src.DestSet))
else:
print src.srcAddr