How does --trace work?
The structure resembles a tree where each node has properties: name, execution_time and children
Two global variables are important: current_frame and trace_root
How does SmartHouseManagement have access to all current instantiated objects?
if __name__ == "__main__" guard this way (objects instantiated inside of guard aren’t in globals)make that adds new objects (just dicts) to a global instances list, SmartHouseManagement class uses this list to iterate over all objectsWhy read chunks of 8192 Bytes?
| struct node* BSTreeDelete(struct node* root, struct node* x) { | |
| u = root; v = NULL; | |
| while (u != x) { | |
| v = u; | |
| if (x->key < u->key) u = u->lft; | |
| else u = u->rgt; | |
| } | |
| if (u->rgt == NULL) { | |
| if (v == NULL) root = u->lft; |
| struct node* BSTTreeInsert(struct node* p, struct node* r) { | |
| struct node* y = NULL; | |
| struct node* x = r; | |
| while (x != NULL) { | |
| // y is one step behind y = x; | |
| if (x -> key < p -> key) { | |
| x = x -> rgt; | |
| } else { |
| struct node* BSTreeSuccAbove(struct node* p, struct node* x) { | |
| struct node* succ = NULL; | |
| while (p != x) { | |
| if (x->key < p->key) { | |
| succ = p; | |
| p = p->lft; | |
| } else if (x->key > p->key) { | |
| p = p->rgt; | |
| } | |
| } |
| BSTRecCount(struct node* p, int x) { | |
| if (p ≠ NULL) { | |
| if (x < p->val) { | |
| return BSTRecCount(p->lft); | |
| } else if (x > p-val) { | |
| return BSTRecCount(p->rgt); | |
| } else { | |
| return 1 + BSTRecCount(p->lft) + BSTRecCount(p->rgt) | |
| } | |
| } else { |
| // Iterative | |
| BSTreeSearch(p,v) | |
| while p ≠ NIL AND p->key≠v do | |
| if v<p->key then | |
| p = p->lft | |
| else | |
| p = p->rgt; | |
| return p; | |
| // Recursive |
| infix(struct node* p = { | |
| if (p ≠ NULL) { | |
| if (needParanthesis(p, false)) { | |
| printf("("); | |
| infix(p->lft); | |
| printf(")"); | |
| } else { | |
| infix(p->lft); | |
| } | |
| } |
| bool needsParentheses(struct node* p, bool rgt) { | |
| return ( | |
| // (a + b) / c | |
| !rgt && precedence(p) < precedence(p->lft)) || | |
| // case where right operation has precedence | |
| // for example: a + (b * c) | |
| (rgt && precedence(p) < precedence(p->rgt)) || | |