SkillAgentSearch skills...

SortedVectors.jl

Lightweight wrapper to declare that a vector is sorted.

Install / Use

/learn @tpapp/SortedVectors.jl
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

SortedVectors

Lifecycle build codecov.io

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

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> 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

Related Skills

View on GitHub
GitHub Stars6
CategoryDevelopment
Updated1y ago
Forks3

Languages

Julia

Security Score

70/100

Audited on Oct 13, 2024

No findings