{"id":16613184,"url":"https://github.com/c-cube/indexed-set","last_synced_at":"2025-10-29T18:31:01.403Z","repository":{"id":8989183,"uuid":"10737333","full_name":"c-cube/indexed-set","owner":"c-cube","description":"OCaml implementation of indexed sets (inspired from Haskell's ixSet library)","archived":false,"fork":false,"pushed_at":"2015-01-28T18:49:41.000Z","size":236,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-04-20T00:54:15.864Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/c-cube.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-06-17T12:57:04.000Z","updated_at":"2024-04-20T00:54:15.865Z","dependencies_parsed_at":"2022-09-11T02:50:40.017Z","dependency_job_id":null,"html_url":"https://github.com/c-cube/indexed-set","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c-cube%2Findexed-set","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c-cube%2Findexed-set/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c-cube%2Findexed-set/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c-cube%2Findexed-set/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/c-cube","download_url":"https://codeload.github.com/c-cube/indexed-set/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219857402,"owners_count":16556067,"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-10-12T01:46:23.684Z","updated_at":"2025-10-29T18:31:01.083Z","avatar_url":"https://github.com/c-cube.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"indexed-set\n===========\n\nOCaml implementation of indexed sets (inspired from Haskell's ixSet library).\n\n## What?\n\n`IxSet` is an attempt to adapt some of Haskell's\n[ixSet](http://hackage.haskell.org/packages/archive/ixset/1.0.2/doc/html/Data-IxSet.html)\nideas to OCaml.\n\nIt provides a functor on some type that we will designate as `elt`. The result\nis a module providing a set type `S.t`, similar to `Set.S`. Additional **indexes**\ncan be added, to access elements by some of their features.\n\nFor instance, if `elt` is a record containing data about people (an\nextended phone book), let say,\n\n```ocaml\ntype person = {\n    phone : string;\n    name : string; \n    age : int;\n}\n```\n\nThen we can define some indexed set as follows:\n\n```ocaml\nmodule P = struct\n    type t = person\n    let compare p1 p2 = String.compare p1.name p2.name\nend\n\nmodule PersonSet = IxSet.Make(P)\n\nlet ixPhone = PersonSet.idx_fun ~cmp:String.compare (fun p -\u003e [p.phone])\nlet ixName = PersonSet.idx_fun ~cmp:String.compare (fun p -\u003e [p.name])\nlet ixAge = PersonSet.idx_fun ~cmp:Pervasives.compare (fun p -\u003e [p.age])\n\nlet set =\n    let set = PersonSet.empty in\n    let set = PersonSet.add_idx set ixPhone in\n    let set = PersonSet.add_idx set ixName in\n    let set = PersonSet.add_idx set ixAge in\n    set\n\nlet set3 = PersonSet.of_list set\n    [ { phone = \"01.23.45.67.89\";\n        name = \"Georges Abitbol\";\n        age = 42;\n      };\n      { phone = \"01.23.45.67.89\";\n        name = \"Captain Falcon\";\n        age = 0x18;\n      };\n      { phone = \"404.404.404\";\n        name = \"Anne O'Nymous\";\n        age = 0;\n      }\n    ]\n```\n\nWe have defined a module `PersonSet`, that allows us to manipulate indexed\nsets of `person`s.\n\nIndexes can be defined with `PersonSet.idx_fun`, which\nindexes by another type (`string` or `int` here), and requires this type\nto be comparable. It also requires a function that maps `person`s to\na list of such keys. Here, we took a straightforward mapping of a person\nto its age, name and phone number.\n\nThen, we define an empty set `set`, and add our indexes to it\n(`PersonSet.empty_with` is an alternative, using heterogenous lists to specify\nwhich indexes we want). `set3` is defined by adding three persons to `set`.\n\nLet us see in a OCaml prompt:\n\n```ocaml\n$ make\n$ rlwrap ocaml\n\u003e #load \"_build/ixSet.cma\";;\n\u003e PersonSet.by set3 ixAge 42;;\n- : PersonSet.elt list = [{phone = \"01.23.45.67.89\"; name = \"Georges Abitbol\"; age = 42}]\n\u003e PersonSet.by set3 ixPhone \"01.23.45.67.89\"\n- : PersonSet.elt list =\n[{phone = \"01.23.45.67.89\"; name = \"Georges Abitbol\"; age = 42};\n{phone = \"01.23.45.67.89\"; name = \"Captain Falcon\"; age = 24}]\n```\n\nSo, using `PersonSet.by`, we can select on a given index. Notice that\nit returns a list of values, since keys do not have to be injective.\n\nBut we can also\n`filter` using a predicate (it's linear, but using the ordering on key types\nit should be easy to have some efficient ordering filters for this example):\n\n```ocaml\n\u003e PersonSet.filter set3 ixAge (fun x -\u003e x \u003c 40);;\n- : PersonSet.elt list =\n[{phone = \"01.23.45.67.89\"; name = \"Captain Falcon\"; age = 24};\n{phone = \"404.404.404\"; name = \"Anne O'Nymous\"; age = 0}] \n```\n\n\n## License\n\nThe code is free, released under the BSD-2 license. Contributions and\nimprovements to the API are very welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc-cube%2Findexed-set","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fc-cube%2Findexed-set","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc-cube%2Findexed-set/lists"}