-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap_dijkstra.py
77 lines (56 loc) · 1.62 KB
/
bootstrap_dijkstra.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
67
68
69
70
71
72
73
74
75
76
77
import _thread
from enum import Enum
from __future__ import annotations
mutex = _thread.allocate_lock()
class NodeColor(Enum):
WHITE = 0
GREY = 1
BLACK = 2
class Node:
def __init__(self: Node, id: int, left: Node = None, right: Node = None):
self.__id = id
self.__left = left
self.__right = right
self.color = NodeColor.WHITE
# self.__leftmutex = _thread.allocate_lock()
# self.__rightmutex = _thread.allocate_lock()
# self.__colormutex = _thread.allocate_lock()
def shade(self: Node):
# self.__colormutex.acquire()
if (self.color == NodeColor.WHITE):
self.color = NodeColor.GREY
# self.__colormutex.release()
@property
def left(self: Node) -> Node:
return self.__left
@left.setter
def left(self: Node, newleft: Node):
# self.__leftmutex.acquire()
self.__left = newleft
# self.__leftmutex.release()
@property
def right(self: Node) -> Node:
return self.__right
@right.setter
def right(self: Node, newright: Node):
# self.__rightmutex.acquire()
self.__right = newright
# self.__rightmutex.release()
@property
def id(self: Node):
return self.__id
class Graph:
def __init__(self: Graph, num_nodes: int):
self.num_nodes = num_nodes
self.nodes = []
# Add NIL
self.NIL = Node(0)
self.NIL.left = self.NIL
self.NIL.right = self.NIL
self.nodes.append(self.NIL)
for i in range(1, self.__num_nodes):
self.nodes.append(Node(i), self.NIL, self.NIL)
# 3 roots for some reason
self.roots = self.nodes[1:4]
# third root is our free list root
self.free_list = self.nodes[3]