{"id":21358421,"url":"https://github.com/danzigerrr/aisd-project-4-b-tree_with_cache","last_synced_at":"2025-03-16T06:16:59.303Z","repository":{"id":130646081,"uuid":"358146086","full_name":"Danzigerrr/AiSD-Project-4-B-tree_with_cache","owner":"Danzigerrr","description":null,"archived":false,"fork":false,"pushed_at":"2021-05-20T07:43:29.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-22T18:35:27.334Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Danzigerrr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-04-15T06:06:40.000Z","updated_at":"2021-08-11T09:03:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"22dfcef5-4276-48c2-950e-e2e76d88140d","html_url":"https://github.com/Danzigerrr/AiSD-Project-4-B-tree_with_cache","commit_stats":null,"previous_names":["danzigerrr/aisd-project-4-b-tree_with_cache"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Danzigerrr%2FAiSD-Project-4-B-tree_with_cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Danzigerrr%2FAiSD-Project-4-B-tree_with_cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Danzigerrr%2FAiSD-Project-4-B-tree_with_cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Danzigerrr%2FAiSD-Project-4-B-tree_with_cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Danzigerrr","download_url":"https://codeload.github.com/Danzigerrr/AiSD-Project-4-B-tree_with_cache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243830955,"owners_count":20354856,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T05:16:21.768Z","updated_at":"2025-03-16T06:16:59.276Z","avatar_url":"https://github.com/Danzigerrr.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"B-tree_with_cache\nThe goal of this project is to implement a B-tree and to measure an enhanced structure where an amount of cache can be used. \nThe tree is as described during the lecture. I.e. a tree of order t, has to store at least t-1 elements in each node (except the root) and at most 2t-1.\nFirst, to implement B-tree - the basic operations are:\nI x - Construct a tree of order x.\nA x - Add value x to the tree, x is a signed integer. The values added are unique, i.e. there will be no two insertions of the same value (except the case when it was deleted in between).\n? x - Check if the value x is in the tree. If it is present print x: +, otherwise print x: -.\nP   - Print all elements that are in the tree.\nL t - Load a tree, t is the order of the tree. In the next line there is a tree in a format given as follows. A pair of brackets ( ) signify a node. A value signify a record (key in the tree).\n( )   Hence ( ( ( 1 2 ) 3 ( 4 ) 5 ( 6 7 ) ) 8 ( ( 9 ) 10 ( 11 ) )  is a tree:\n                                        (         .           8       .    )\n                                        (  . 3    .  5   .  )   ( . 10  .  )\n                                        ( 1 2 ) ( 4 ) ( 6 7 )   ( 9 ) ( 11 )\nS   - Save the tree in the format described above.\nR x - Remove an element x from the tree. The element may be present or not. Hence the operation might not change the elements in the tree, but may force reorganization.\n'#'  - Ignore the line.\nX   - End the program.\nC x q1, q2, ... - Calculate an impact of a hypothetical cache. I.e. assume that you are given a set of quarries q1, ..., qn (the list of quarries ends by a new line character). \nThe program can store the result of the quarry in a cache of size x. \nHence, if the next quarried entry was already visited, the program does not have to visit B-tree, but may simply read the data from cache. \nDue to the fact that the size of the cache is much smaller than the size of B-tree, only chosen entries can be stored. \nThe policy that has to be implemented is First-In-First-Out. \nI.e. the first entry that was read to the cache is removed from it, when some other entry is read and the result is added to the cache. \nKeep in mind, that a result \"No found\" is a proper result to store in the cache.\nThe measure of the impact of the cache is given by the number of accesses to the disk (measured as depth in the B-tree).\n   As an example consider the tree from point L and series of quarries given by C 2   1 2 1 1 3 1. \nThe measure without cache is 17. \nThe measure with cache is 3 + 3 ( to fill the cache ) + 0 + 0 ( free loads due to the cache) + 2 + 3 (sadly, the entry 1 was removed from the cache, hence it has to be re-loaded) = 11. \n   A bonus can be earned, if other reasonable cache policy is proposed and it's impact (in disk accesses) is measured.\n\nGrades:\n - I A ? - together gives 25%\n - P     - 5%\n - L  S  - 15%\n - R     - 40%\n - C     - 15% (+10% bonus, if other cache policy than discussed is proposed and measured (calculating the impact on the number of disk accesses is enough))\n\nA penalty may be given for hard-coding the program for tests, i.e., the program shall work for any reasonable input. \nBounding the order of tree by 2/10/10000 (by for example allocating always an array of such a size for each node) is not proper. \nPlease allocate the memory dynamically. \n\nAs a reminder, no algorithms/data structures from STL, like vectors, lists, maps, etc. can be used. All general rules still apply. \n\nTests:\n1      : sanity check (failing = 0 from this project)\n2 - 5  : tests for I A ?\n6 -7   : tests for P\n8 - 11 : tests for L\n12 - 13: tests for S\n14 - 17: tests for R\n18 - 22: tests for C\nThe tests assume that ? /C - operation does not change the structure of the three. Otherwise, they should be not dependent on the details of the implementation.\n\nExamples:\n\n1) Input:\nI 2\nA 2\nA 4\nA 5\nA 1\n? 2\n? 3\nX\n\n1) Output:\n2 +\n3 -\n\n\n2) Input:\nI 2\nA 2\nA 4\nA 5\nA 1\nP\nX\n\n2) Output:\n1 2 4 5\n\n\n3) Input:\nI 2    \nA 2\nA 4\nA 5\nA 1\nS\nX\n\n3) Output:\n2\n( ( 1 2 ) 4 ( 5 ) )\n\n\n4) Input:\nL 2\n( ( 1 2 ) 4 ( 5 ) )\n? 1\n? 10\nX\n\n4) Output:\n1 +\n10 -\n\n\n5) Input:\nI 2    \nA 2\nA 4\nA 5\nA 1\n? 1\nR 1\n? 1\nA 1\n? 1\nX\n\n5) Output:\n1 +\n1 -\n1 +\n\n\n6) Input:\nI 2    \nA 2\nA 4\nA 5\nC 2 2 10 2 2 4 2\nX\n\n6) Output:\nNO CACHE: 6 CACHE: 4\n\nTips: \nImplement first I A ? - to see that the program works at all. \nThen implement P and S before starting with D. \nThese operations (together with \"health checks\" that you should implement) should allow you to implement D operations more easily.\n\nDo not optimize the code before checking that all the operations are working as required, it might be not even necessary. \nPrecisely, you can assume that the order of tree is small.\nHence, the gain from implementing a more clever check for a key in a given node (using bisection, balanced tree, etc.) is not necessary.\n\nFor delete operation decouple merging and deleting. \nNotice that if a tree has structure and we would like to remove Y\n                                                     ( ...  X    .   Y   .    Z ... )\n                                                              ( a b ) ( c d )\n\nfirst we can change the structure to \n                                                        ( ...  X    .    Z ... )\n                                                              ( a b Y c d )\nAnd recursively call for removal of Y in the new node ( a b Y c d). \n\nSimilarly, the splitting and adding can be decoupled.\nIf the root was merged it might be the case that the old root is composed of a single pointer. \nThe height of the tree has to be decreased.\n\nKeep in mind that when \"shifting\" the pointers from node to node the parent of the pointered nodes changes. \n\nAlso, try to write a few functions that will measure a \"health\" of the program, if all the pointers are valid, nodes have good sizes etc. \n\nIntroduction to Algorithms by T. H. Cormen et al. is a good reference.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanzigerrr%2Faisd-project-4-b-tree_with_cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanzigerrr%2Faisd-project-4-b-tree_with_cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanzigerrr%2Faisd-project-4-b-tree_with_cache/lists"}