-
Notifications
You must be signed in to change notification settings - Fork 0
/
pnode.py
52 lines (40 loc) · 965 Bytes
/
pnode.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
# P-Node will store process information
#@author Josue Ruiz CS 431
class pnode:
def __init__(self, pid):
self.pid = pid
self.jobs = {}
self.counter = 0
self.time_left = 0
self.lock = 0
self.total = 0
def add(self, job):
self.jobs.append(job)
def current(self):
if self.counter > len(self.jobs)-1:
return -1
else:
return self.jobs[self.counter]
def next(self):
self.counter = self.counter + 1
def isOdd(self):
if self.jobs[self.counter] % 2 == 0:
return True
else:
return False
def set(self, result):
self.jobs[self.counter] = result
def done(self):
num = "%02d" % (self.pid)
string = "\tP"+str(num) + " is done"
return string
def sort_list(self):
self.jobs.sort()
def add_total(self):
for x in range(len(self.jobs)):
self.total = self.total + self.jobs[x]
def __str__(self):
string = str(self.pid)+ " "
for x in range(len(self.jobs)):
string += str(self.jobs[x]) + " "
return string