-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.py
More file actions
56 lines (39 loc) · 1.05 KB
/
node.py
File metadata and controls
56 lines (39 loc) · 1.05 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
__author__ = 'titus'
from box import empty
class Node(dict):
"""
BST - Node
"""
def __init__(self, **kw):
dict.__init__(self, kw)
self.__dict__ = self
if 'leaf' not in self:
self.leaf = False
if 'children' not in self:
self.children = []
if 'height' not in self:
self.height = 1
if 'bbox' not in self:
self.bbox = empty()
def __getstate__(self):
return self
def __setstate__(self, state):
self.update(state)
self.__dict__ = self
def __getattr__(self, item):
# only gets called if key is missing
if item not in self.__dict__:
raise Exception("invalid attribute")
def __lt__(self, other):
return 0
def __le__(self, other):
return 0
def __gt__(self, other):
return 0
def __ge__(self, other):
return 0
def hasattr(self, attr):
return attr in self.__dict__
@property
def size(self):
return len(self.children)