https://github.com/tpapp/sortedvectors.jl
Lightweight wrapper to declare that a vector is sorted.
https://github.com/tpapp/sortedvectors.jl
Last synced: over 1 year ago
JSON representation
Lightweight wrapper to declare that a vector is sorted.
- Host: GitHub
- URL: https://github.com/tpapp/sortedvectors.jl
- Owner: tpapp
- License: mit
- Created: 2018-11-20T12:55:57.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-09-30T14:21:34.000Z (over 1 year ago)
- Last Synced: 2025-02-28T16:20:13.206Z (over 1 year ago)
- Language: Julia
- Size: 26.4 KB
- Stars: 6
- Watchers: 3
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SortedVectors

[](https://github.com/tpapp/SortedVectors.jl/actions?query=workflow%3ACI)
[](http://codecov.io/github/tpapp/SortedVectors.jl?branch=master)
A very lightweight Julia package to declare that a vector is sorted.
## Installation
The package is registered. Type `]` to enter `pkg` mode, and install with
```julia
pkg> add SortedVectors
```
## Features
- lightweight wrapper
- customizable order (any `Base.Order.Ordering`)
- constructor sorts argument by default, this can be skipped, or just verified
- `setindex!` checks that order is maintained
- fast implementation for `in`
## Documentation
See the docstring for `SortedVector`, the only exported symbol.
## Example
``` julia
julia> using SortedVectors
julia> sv = SortedVector([1, 3, 4])
3-element SortedVector{Int64, Vector{Int64}, Base.Order.ForwardOrdering}:
1
3
4
julia> sv[2]
3
julia> 2 ∈ sv
false
julia> sv[2] = 7
ERROR: ArgumentError: Order.lt(order, x, sorted_contents[i + 1]) must hold. Got
Order.lt => lt
order => ForwardOrdering()
x => 7
sorted_contents[i + 1] => 4
Stacktrace:
[1] throw_check_error(info::Any)
@ ArgCheck ~/.julia/packages/ArgCheck/CA5vv/src/checks.jl:280
[2] setindex!(sorted_vector::SortedVector{Int64, Vector{Int64}, Base.Order.ForwardOrdering}, x::Int64, i::Int64)
@ SortedVectors ~/code/julia/SortedVectors/src/SortedVectors.jl:104
```