| 1 | = Data structures = |
| 2 | |
| 3 | A well-designed data structure allows a variety of critical operations to be |
| 4 | performed, using as little resources, both execution time and memory space, as |
| 5 | possible. Moreover a carefully chosen data structure will allow a more efficient |
| 6 | algorithm to be used; consequently such choice assume a primary importance in |
| 7 | this project. |
| 8 | [[BR]] |
| 9 | The two fundamental data structures on which Phase 1 layer is founded are lists |
| 10 | and trees, implemented in various ways, depending on the singular case |
| 11 | evaluations. |
| 12 | |
| 13 | Here below we are going to describe the two most significative flavour of them. |
| 14 | |
| 15 | == 1. Linear single linked list == |
| 16 | This simple data structure has been choosen for trivial structures |
| 17 | implementation. We are talking about lists of non-allocated PCBs or SDs: |
| 18 | respectively pcbFree and semdFree. |
| 19 | |
| 20 | In fact, because of element insertion and deletion may involve only the first |
| 21 | one, a stack with a ''O(1)'' computational cost is what we was looking for. And |
| 22 | is what we implemented with a linear single linked list, appreciating its |
| 23 | simplicity. |
| 24 | |
| 25 | |
| 26 | == 2. Circular double linked list == |
| 27 | List management operations, such as element insertion and deletion, require |
| 28 | predecessor and successor updating. Because of this, a previous element pointer |
| 29 | (`p_prev`) is added to the PCB standard structure, performing these operations |
| 30 | scanning the list only once. |
| 31 | |
| 32 | Kaya Phase 1 will take advantage of double circularly linked list benefits in |
| 33 | every processes queue, which is widely used by operating system. |
| 34 | |
| 35 | |
| 36 | == 3. Semaphore binary tree == |
| 37 | The importance of the '''choice''' of data structure increases directly with the |
| 38 | performance relevance and for semaphore descriptors management becomes a primary |
| 39 | goal. That is because semaphores queue's phisical address is obfuscated in a |
| 40 | higher level view, so Phase 1 layer must encapsulate the association between |
| 41 | semaphore address (semAdd) and its queue into the Semaphore descriptors (SDs). |
| 42 | |
| 43 | Such association must be searched between them and if they are managed in a sorted |
| 44 | structure computational costs decrease, avoiding scanning everyone. For this |
| 45 | reason we opted for a data structure that is more complex and difficult to |
| 46 | mantain but, on the other hand, is more performant and scalable: a binary search |
| 47 | tree. |
| 48 | |
| 49 | Let us show in detail a BSTs '''comparison''' with sorted list. |
| 50 | [[BR]] |
| 51 | The major part of mantainence costs depends on the fact that it is sorted and, |
| 52 | consequently, on the search cost. In fact, while a list search costs ''O(n)'', a |
| 53 | binary tree takes only ''O(log(n))'', because of the number of scanned elements |
| 54 | is at most equal to the tree height. By the way, input distribution influences |
| 55 | BST's height in a determining way, deciding tree balance, making ''O(log(n))'' |
| 56 | an estimate of the average case cost. In particularly adverse situations BSTs |
| 57 | collapse into a ''f**ked/s**t'' list. |
| 58 | [[BR]] |
| 59 | Summing up, in order to appreciate BSTs performance improvements and scalability, |
| 60 | input cardinality should be sufficiently large and well-distributed. |
| 61 | |
| 62 | Like often happens, performance and '''memory usage''' risk to collide and a good |
| 63 | compromise is needed. |
| 64 | [[BR]] |
| 65 | Therefore we tried to limit wastes, just single-linking the tree with `s_rightC` |
| 66 | and `s_leftC` pointers, increasing module complexity and consequent |
| 67 | implementation and mantainance [wiki:doc/devel difficulties]. |