{"id":15057519,"url":"https://github.com/denius/unitrangessortedsets.jl","last_synced_at":"2026-01-03T04:40:15.734Z","repository":{"id":65205214,"uuid":"580622640","full_name":"denius/UnitRangesSortedSets.jl","owner":"denius","description":"Sorted set of unit ranges.","archived":false,"fork":false,"pushed_at":"2024-02-15T15:01:41.000Z","size":187,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-20T22:57:54.111Z","etag":null,"topics":["datastructures","julia","julialang"],"latest_commit_sha":null,"homepage":"","language":"Julia","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/denius.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-21T02:41:13.000Z","updated_at":"2022-12-21T02:48:35.000Z","dependencies_parsed_at":"2024-02-15T15:52:33.507Z","dependency_job_id":null,"html_url":"https://github.com/denius/UnitRangesSortedSets.jl","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denius%2FUnitRangesSortedSets.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denius%2FUnitRangesSortedSets.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denius%2FUnitRangesSortedSets.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denius%2FUnitRangesSortedSets.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/denius","download_url":"https://codeload.github.com/denius/UnitRangesSortedSets.jl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243761996,"owners_count":20343971,"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":["datastructures","julia","julialang"],"created_at":"2024-09-24T22:07:35.379Z","updated_at":"2026-01-03T04:40:15.683Z","avatar_url":"https://github.com/denius.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UnitRangesSortedSets\n\n[![Build Status](https://github.com/denius/UnitRangesSortedSets.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/denius/UnitRangesSortedSets.jl/actions/workflows/CI.yml?query=branch%3Amain)\n[![Coverage](https://codecov.io/gh/denius/UnitRangesSortedSets.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/denius/UnitRangesSortedSets.jl)\n\n\nSorted set of `UnitRange`s. Sorted in ascending order and no one range overlaps with another.\n\n    mutable struct UnitRangesSortedSet{K, TU} \u003c: AbstractSet{TU}\n\n`UnitRangesSortedSet` can be created like the standard `Set`:\n\n```julia\n    UnitRangesSortedSet(somecontainer)\n```\n\nfor example:\n```julia\njulia\u003e using UnitRangesSortedSets\n\njulia\u003e UnitRangesSortedSet((1, 2, 4))\nUnitRangesSortedSet{Int64} with 2 elements:\n  1:2\n  4:4\n\njulia\u003e UnitRangesSortedSet(('a':'z', 'α':'ω'))\nUnitRangesSortedSet{Char} with 2 elements:\n  'a':'z'\n  'α':'ω'\n\njulia\u003e Random.seed!(1234);\n\njulia\u003e UnitRangesSortedSet(rand(1:20, 10))\nUnitRangesSortedSet{Int64} with 6 elements:\n   5:5\n   7:8\n  10:11\n  15:16\n  18:18\n  20:20\n```\n\nor with `push!`:\n\n```julia\njulia\u003e urs = UnitRangesSortedSet{Int}()\nUnitRangesSortedSet{Int64}()\n\njulia\u003e push!(urs, 1)\nUnitRangesSortedSet{Int64} with 1 element:\n  1:1\n\njulia\u003e push!(urs, 2)\nUnitRangesSortedSet{Int64} with 1 element:\n  1:2\n\njulia\u003e push!(urs, 10:12)\nUnitRangesSortedSet{Int64} with 2 elements:\n   1:2\n  10:12\n```\n\nIterating over set of ranges:\n\n```julia\njulia\u003e for r in urs @show(r) end\nr = 1:2\nr = 10:12\n\njulia\u003e for r in urs, i in r @show(i) end\ni = 1\ni = 2\ni = 10\ni = 11\ni = 12\n\njulia\u003e for i in Iterators.flatten(urs) @show(i) end\ni = 1\ni = 2\ni = 10\ni = 11\ni = 12\n\njulia\u003e collect(urs)\n2-element Vector{UnitRange{Int64}}:\n 1:2\n 10:12\n```\n\nDeleting elements and ranges:\n```julia\njulia\u003e delete!(urs, 10:11)\nUnitRangesSortedSet{Int64} with 2 elements:\n   1:2\n  12:12\n\njulia\u003e delete!(urs, 1)\nUnitRangesSortedSet{Int64} with 2 elements:\n   2:2\n  12:12\n```\n\n# SubSet\n\nIt is possible to create the subset of `UnitRangesSortedSet`, like a `view` for `Array`s:\n```julia\njulia\u003e urs = UnitRangesSortedSet((1:2, 10:12))\nUnitRangesSortedSet{Int64} with 2 elements:\n   1:2\n  10:12\n\njulia\u003e ss = subset(urs, 0:10)\n2-element subset(UnitRangesSortedSet{Int64}, DataStructures.Tokens.IntSemiToken(3):DataStructures.Tokens.IntSemiToken(4)):\n   1:2\n  10:10\n```\n\nThe `subset` object is an static, iterable view of the container.\n\n# Two types of `UnitRangesSortedSet`\n\nThe first type `UnitRangesSortedSet{K}` contains `SortedDict{K,K}`,\n```julia\nmutable struct UnitRangesSortedSet{K,TU} \u003c: AbstractUnitRangesSortedContainer{K,TU}\n    ranges::SortedDict{K,K,FOrd}\nend\n```\nwhere each element of the dict contains the `first(range)` as key, and the `last(range)` as value.\n\nThe second implementation `VecUnitRangesSortedSet{K}` is based on `Vector{K}`s:\n```julia\nmutable struct VecUnitRangesSortedSet{K,TU} \u003c: AbstractUnitRangesSortedContainer{K,TU}\n    rstarts::Vector{K}\n    rstops::Vector{K}\nend\n```\nwhere `rstarts::Vector{K}` and `rstops::Vector{K}` are the starts and stops of\nthe ranges respectively.\n\nThese two implementations have a similar API but different speeds.\n\nIn either case, both of them can be converted to each other using the appropriate constructor.\n\n# Benchmarking\n\nAll results of benchmarks in the file [test-bench-results.md](test/test-bench-results.md).\n\nMain conclusions of benchmarking:\n* in any case of iterating over `range`s or consecutively element-wise in any `AbstractUnitRangesSortedSet` is\n  much much faster then in any another variant.\n* element-wise iterating, and over ranges iterating, in `VecUnitRangesSortedSet` is faster by\n  the orders over `UnitRangesSortedSet`.\n* when created from elements in random order, `UnitRangesSortedSet` is vastly superior\n  to the `Vec` variant.\n* creating in consecutively element-wise order, `VecUnitRangesSortedSet` is an order of magnitude faster\n  than creating a set of the second type.\n* in searching operations (`in()`, `subset()`) `VecUnitRangesSortedSet` variant is faster:\n  in Julia-v1.6 it is twice as fast, in Julia-1.8 the speedup is about 20-30%.\n* if your range diapason is about some millions of elements then the `BitSet` is the best choice\n  for creating. And then `convert(UnitRangesSortedSet, someBitSetContainer)` is the solution to\n  have the fast iteration over container.\n\n### Note\n\nFor `Char`, `StepRange{Char,UInt8}` will be used, with a step of `oneunit(UInt8)` if needed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenius%2Funitrangessortedsets.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdenius%2Funitrangessortedsets.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenius%2Funitrangessortedsets.jl/lists"}