From 573ba8af0bf540b24ab84cd85756f2fbf23f8fbd Mon Sep 17 00:00:00 2001 From: joshday Date: Mon, 16 Mar 2020 19:05:59 -0400 Subject: [PATCH] improve Part domains --- Project.toml | 2 +- src/part.jl | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 752539f..6fa912a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "OnlineStatsBase" uuid = "925886fa-5bf2-5e8e-b522-a9147a512338" -version = "1.2.0" +version = "1.2.1" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" diff --git a/src/part.jl b/src/part.jl index cbc46fd..3ed9765 100644 --- a/src/part.jl +++ b/src/part.jl @@ -1,5 +1,5 @@ #-----------------------------------------------------------------------------# Part -struct Part{D, O} <: OnlineStat{TwoThings} +struct Part{D, O<:OnlineStat} <: OnlineStat{TwoThings} stat::O domain::D end @@ -53,11 +53,12 @@ end mutable struct ClosedInterval{T} first::T last::T + ClosedInterval(a::T, b::T) where {T} = a < b ? new{T}(a,b) : error("Arguments must be ordered") end Base.show(io::IO, b::ClosedInterval) = print(io, "ClosedInterval: [$(b.first), $(b.last)]") Base.in(x, bucket::ClosedInterval) = bucket.first ≤ x ≤ bucket.last Base.isless(a::ClosedInterval, b::ClosedInterval) = isless(a.first, b.first) -function Base.merge!(a::ClosedInterval, b::ClosedInterval) +function Base.merge!(a::ClosedInterval, b::ClosedInterval, astat, bstat) a.first = min(a.first, b.first) a.last = max(a.last, b.last) a