{"id":21348061,"url":"https://github.com/a-gx/generalised_odd-even-merge","last_synced_at":"2025-10-10T16:23:00.639Z","repository":{"id":221173938,"uuid":"711873377","full_name":"A-GX/Generalised_Odd-Even-Merge","owner":"A-GX","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-06T13:50:28.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-06T14:41:52.736Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/A-GX.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,"publiccode":null,"codemeta":null}},"created_at":"2023-10-30T10:50:52.000Z","updated_at":"2025-03-06T13:50:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"86656050-15ba-4c55-a2f1-c06a54c102cd","html_url":"https://github.com/A-GX/Generalised_Odd-Even-Merge","commit_stats":null,"previous_names":["a-gx/generalised_odd-even-merge"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/A-GX%2FGeneralised_Odd-Even-Merge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/A-GX%2FGeneralised_Odd-Even-Merge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/A-GX%2FGeneralised_Odd-Even-Merge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/A-GX%2FGeneralised_Odd-Even-Merge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/A-GX","download_url":"https://codeload.github.com/A-GX/Generalised_Odd-Even-Merge/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243822727,"owners_count":20353533,"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-22T02:17:46.899Z","updated_at":"2025-10-10T16:22:55.621Z","avatar_url":"https://github.com/A-GX.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nCrate [generalised\\_odd\\_even\\_merge]\n===========================================================================\n\n\n[Generalised Odd-Even Merge Algorithm with constant memory](#generalised-odd-even-merge-algorithm-with-constant-memory)\n-----------------------------------------------------------------------------------------------------------------------\n\nThis is the official library (and implementation) of the paper **\\[“Odd-Even Merging Network: a Software Implementation for Arbitrary Lengths” - Antoine Gansel\\]**. This algorithm follows the description of Odd-Even merging networks from the paper \\[“Sorting Networks and their applications” - K. E. Batcher - 1968\\] You can find the proof of correctness in our own paper (mentionned earlier).\n\nYou can find example for every functions and trait in their respective module descriptions.\n\n[Modules](#modules)\n-------------------\n\n\n\n\n## [necessary\\_traits](#necessary_traits)\n\n\n#### Description\n\nWe expect you to run the merge or sorting function on a list-like structure. For generalisation sake, you need to generate the structure yourself such as to be able to define the comparison and swapping operations for any sort of data you may be using.\n\n#### Example\n```rs\nuse generalised-odd-even-merge::necessary_traits::CompareSwap;\n    \n// (1) Create your data structure\n#[derive(Debug)]\npub struct DataBase {\n    pub row: Vec\u003cusize\u003e,\n}\n    \n// (2) Implement the CompareSwap type for you structure\nimpl CompareSwap for DataBase {\n    fn compare_swap(\u0026mut self, a: usize, b: usize) $\\rightarrow$ std::io::Result\u003c()\u003e {\n        let cmp:usize = if self.row[a]\u003e=self.row[b] {0} else {1};\n        let tempo_a = self.row[a]*cmp + self.row[b]*(1-cmp);\n        self.row[b] = self.row[b]*cmp + self.row[a]*(1-cmp);\n        self.row[a] = tempo_a;\n        Ok(())\n    }\n}\n```\n\n## [merge](#merge)\n\n#### Description\n\n*   Here, we denote by “position” the index of an element in the original list, and by “index” the index of an element in the sub-list (i.e in when inside a recurisve step). To illustrate why this distinction is usefull : take an element at index 2 in one of the recursive step, its actual position in the full list can perfectly be 7. In this case, the aforementionned element is considered to be an “even” element in the sub-list built for a recursive step on the “odd” elements of the intial list.\n\n\n#### Parameters\n``fn odd_even_merge\u003cT: CompareSwap\u003e ( list:\u0026mut T, n_l: usize, n_r: usize, s_l: usize, s_r: usize, step: usize )``\n*   list:\u0026mut T $\\rightarrow$  mutable structure T. See example in necessary\\trait module\n    \n*   n\\_l: usize $\\rightarrow$ length of the left sublist\n    \n*   s\\_l: usize $\\rightarrow$ starting index of the left sublist\n    \n*   n\\_r: usize $\\rightarrow$ length of the right sublist\n    \n*   s\\_r: usize $\\rightarrow$ starting indec of the right sublist\n    \n*   step: usize $\\rightarrow$ necessary step to go from an element to the next one INSIDE the sublist (NOT IN BETWEEN SUBLISTS)\n    \n\n#### Example\n\n**/!\\\\** This example use the DataBase type defined for the example in the _**necessary\\_traits**_ module description **/!\\\\**\n```rs \nuse generalised-odd-even-merge::merge::odd_even_merge;\nuse rand::Rng;\n    \nfn is_ordered(list: Vec\u003cusize\u003e) {\n    let mut res = true;\n    for i in 0..list.len()-1 {\n        res = res \u0026\u0026 list[i] \u003c= list [i+1];\n    }\n    assert!(res);\n}\n\nfn main () {\n    let mut rng = rand::thread_rng();\n    for j in 2..100 {\n        for i in 0..j*j {\n            // Generate random list\n            let mut list = DataBase { row: (0..j).map(|_| rng.gen_range(0..1000)).collect() };\n            println!(\"{:?}\",list.row);\n\n            // make the list into two ordered list of random size\n            let pivot: usize = rng.gen_range(0..j-1);\n            odd_even_merge_sort(\u0026mut list, 0, pivot);\n            odd_even_merge_sort(\u0026mut list, pivot, j-pivot);\n            print!(\"{:?} -- pivot: {}\\n\",list.row,pivot);\n\n            // merge the two list of random sizes\n            odd_even_merge(\u0026mut list, pivot, j-pivot, 0, pivot, 1);\n\n            print!(\"{:?} -- i: {} - j: {}\\n\",list.row,i,j);\n            is_ordered(list.row);\n        }\n    }\n}\n```\n\n## [sort](#sort)\n\n#### Description\n\nRecursively sort a list using the generalised Odd-Even merging networg : split the initial list recursively until it obtains list of size 1 (hence sorted) and then feed those sorted list to the merging network.\n\n#### Parameters\n``fn odd_even_merge_sort\u003cT: CompareSwap\u003e( db:\u0026mut T, start: usize, len: usize )``\n\n*   list:\u0026mut T $\\rightarrow$ mutable structure T. See example in necessary\\trait module\n    \n*   start: usize $\\rightarrow$ the starting index of the (sub-)list to sort. Initial value is usually 0\n    \n*   len: usize $\\rightarrow$ the lenght of the (sub-)list to sort. Intitall value is usually list.len()\n    \n\n#### Example\n\n**/!\\\\** This example use the DataBase type defined for the example in the _**necessary\\_traits**_ module description **/!\\\\**\n```rs\nuse generalised-odd-even-merge::merge::odd_even_merge;\nuse rand::Rng;\n    \nfn is_ordered(list: Vec\u003cusize\u003e) {\n    let mut res = true;\n    for i in 0..list.len()-1 {\n        res = res \u0026\u0026 list[i] \u003c= list [i+1];\n    }\n    assert!(res);\n}\n\nfn main () {\n    let mut rng = rand::thread_rng();\n    for j in 2..100 {\n        for i in 0..j*j {\n            // Generate a random list\n            let mut list = DataBase { row: (0..j).map(|_| rng.gen_range(0..1000)).collect() };\n            println!(\"{:?}\",list.row);\n            \n            // order the list\n            odd_even_merge_sort(\u0026mut list, 0, j);\n\n            print!(\"{:?} -- i: {} - j: {}\\n\",list.row,i,j);\n            is_ordered(list.row);\n        }\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa-gx%2Fgeneralised_odd-even-merge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fa-gx%2Fgeneralised_odd-even-merge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa-gx%2Fgeneralised_odd-even-merge/lists"}