Skip to content

Commit 6748dc6

Browse files
authored
Require 0.6, fix 0.7 depwarns (#59)
1 parent acc31a4 commit 6748dc6

File tree

7 files changed

+33
-34
lines changed

7 files changed

+33
-34
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
language: julia
33
os:
44
- linux
5-
- osx
65
julia:
7-
- 0.5
86
- 0.6
97
- nightly
108
notifications:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Primes.jl
22

3-
[![Primes](http://pkg.julialang.org/badges/Primes_0.5.svg)](http://pkg.julialang.org/?pkg=Primes)
43
[![Primes](http://pkg.julialang.org/badges/Primes_0.6.svg)](http://pkg.julialang.org/?pkg=Primes)
4+
[![Primes](http://pkg.julialang.org/badges/Primes_0.7.svg)](http://pkg.julialang.org/?pkg=Primes)
55
[![Build Status](https://travis-ci.org/JuliaMath/Primes.jl.svg?branch=master)](https://travis-ci.org/JuliaMath/Primes.jl)
66
[![Windows Build](https://ci.appveyor.com/api/projects/status/ao64pk44lwo0092r/branch/master?svg=true)](https://ci.appveyor.com/project/ararslan/primes-jl/branch/master)
77
[![Coverage Status](https://coveralls.io/repos/github/JuliaMath/Primes.jl/badge.svg?branch=master)](https://coveralls.io/github/JuliaMath/Primes.jl?branch=master)

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
julia 0.5
1+
julia 0.6
22
Compat 0.30.0

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
environment:
22
matrix:
3-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
4-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
3+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
4+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
55
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
66
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
77

src/Primes.jl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ else
1212
end
1313

1414
using Base: BitSigned
15-
using Base.Checked.checked_neg
15+
using Base.Checked: checked_neg
1616

1717
export ismersenneprime, isrieselprime, nextprime, prevprime, prime, prodfactors, radical, totient
1818

@@ -101,7 +101,7 @@ function primesmask(lo::Int, hi::Int)
101101
end
102102
return sieve
103103
end
104-
primesmask{T<:Integer}(lo::T, hi::T) = lo hi typemax(Int) ? primesmask(Int(lo), Int(hi)) :
104+
primesmask(lo::Integer, hi::Integer) = lo hi typemax(Int) ? primesmask(Int(lo), Int(hi)) :
105105
throw(ArgumentError("Both endpoints of the interval to sieve must be ≤ $(typemax(Int)), got $lo and $hi."))
106106

107107
primesmask(limit::Int) = primesmask(1, limit)
@@ -240,7 +240,7 @@ isprime(n::Int128) = n < 2 ? false :
240240
# https://en.wikipedia.org/wiki/Pollard%27s_rho_algorithm
241241
# http://maths-people.anu.edu.au/~brent/pub/pub051.html
242242
#
243-
function factor!{T<:Integer,K<:Integer}(n::T, h::Associative{K,Int})
243+
function factor!(n::T, h::AbstractDict{K,Int}) where {T<:Integer,K<:Integer}
244244
# check for special cases
245245
if n < 0
246246
h[-1] = 1
@@ -303,14 +303,14 @@ julia> collect(factor(0))
303303
0=>1
304304
```
305305
"""
306-
factor{T<:Integer}(n::T) = factor!(n, Factorization{T}())
306+
factor(n::T) where {T<:Integer} = factor!(n, Factorization{T}())
307307

308308

309309
"""
310310
factor(ContainerType, n::Integer) -> ContainerType
311311
312312
Return the factorization of `n` stored in a `ContainerType`, which must be a
313-
subtype of `Associative` or `AbstractArray`, a `Set`, or an `IntSet`.
313+
subtype of `AbstractDict` or `AbstractArray`, a `Set`, or an `BitSet`.
314314
315315
```julia
316316
julia> factor(DataStructures.SortedDict, 100)
@@ -342,18 +342,18 @@ julia> factor(Set, 100)
342342
Set([2,5])
343343
```
344344
"""
345-
factor{T<:Integer, D<:Associative}(::Type{D}, n::T) = factor!(n, D(Dict{T,Int}()))
346-
factor{T<:Integer, A<:AbstractArray}(::Type{A}, n::T) = A(factor(Vector{T}, n))
347-
factor{T<:Integer}(::Type{Vector{T}}, n::T) =
345+
factor(::Type{D}, n::T) where {T<:Integer, D<:AbstractDict} = factor!(n, D(Dict{T,Int}()))
346+
factor(::Type{A}, n::T) where {T<:Integer, A<:AbstractArray} = A(factor(Vector{T}, n))
347+
factor(::Type{Vector{T}}, n::T) where {T<:Integer} =
348348
mapreduce(collect, vcat, Vector{T}(), [repeated(k, v) for (k, v) in factor(n)])
349-
factor{T<:Integer, S<:Union{Set,IntSet}}(::Type{S}, n::T) = S(keys(factor(n)))
350-
factor{T<:Any}(::Type{T}, n) = throw(MethodError(factor, (T, n)))
349+
factor(::Type{S}, n::T) where {T<:Integer, S<:Union{Set,BitSet}} = S(keys(factor(n)))
350+
factor(::Type{T}, n) where {T<:Any} = throw(MethodError(factor, (T, n)))
351351

352352
"""
353353
prodfactors(factors)
354354
355355
Compute `n` (or the radical of `n` when `factors` is of type `Set` or
356-
`IntSet`) where `factors` is interpreted as the result of
356+
`BitSet`) where `factors` is interpreted as the result of
357357
`factor(typeof(factors), n)`. Note that if `factors` is of type
358358
`AbstractArray` or `Primes.Factorization`, then `prodfactors` is equivalent
359359
to `Base.prod`.
@@ -365,8 +365,8 @@ julia> prodfactors(factor(100))
365365
"""
366366
function prodfactors end
367367

368-
prodfactors{K}(factors::Associative{K}) = isempty(factors) ? one(K) : prod(p^i for (p, i) in factors)
369-
prodfactors(factors::Union{AbstractArray, Set, IntSet}) = prod(factors)
368+
prodfactors(factors::AbstractDict{K}) where {K} = isempty(factors) ? one(K) : prod(p^i for (p, i) in factors)
369+
prodfactors(factors::Union{AbstractArray, Set, BitSet}) = prod(factors)
370370

371371
"""
372372
Base.prod(factors::Primes.Factorization{T}) -> T
@@ -388,7 +388,7 @@ julia> radical(2*2*3)
388388
"""
389389
radical(n) = prod(factor(Set, n))
390390

391-
function pollardfactors!{T<:Integer,K<:Integer}(n::T, h::Associative{K,Int})
391+
function pollardfactors!(n::T, h::AbstractDict{K,Int}) where {T<:Integer,K<:Integer}
392392
while true
393393
c::T = rand(1:(n - 1))
394394
G::T = 1
@@ -510,7 +510,7 @@ Compute the Euler totient function of the number whose prime factorization is
510510
given by `f`. This method may be preferable to [`totient(::Integer)`](@ref)
511511
when the factorization can be reused for other purposes.
512512
"""
513-
function totient{T <: Integer}(f::Factorization{T})
513+
function totient(f::Factorization{T}) where T <: Integer
514514
if !isempty(f) && first(first(f)) == 0
515515
throw(ArgumentError("ϕ(0) is not defined"))
516516
end
@@ -541,9 +541,9 @@ function add_!(n::BigInt, x::Int)
541541
# TODO: Change `Any` to `Ref{BigInt}` when 0.6 support is dropped.
542542
# The two have the same effect but `Ref{BigInt}` won't be optimized on 0.6.
543543
if x < 0
544-
ccall((:__gmpz_sub_ui, :libgmp), Void, (Any, Any, Culong), n, n, -x)
544+
ccall((:__gmpz_sub_ui, :libgmp), Cvoid, (Any, Any, Culong), n, n, -x)
545545
else
546-
ccall((:__gmpz_add_ui, :libgmp), Void, (Any, Any, Culong), n, n, x)
546+
ccall((:__gmpz_add_ui, :libgmp), Cvoid, (Any, Any, Culong), n, n, x)
547547
end
548548
n
549549
end
@@ -638,7 +638,7 @@ function prevprime(n::Integer, i::Integer=1)
638638
end
639639

640640
"""
641-
prime{T}(::Type{T}=Int, i::Integer)
641+
prime(::Type{<:Integer}=Int, i::Integer)
642642
643643
The `i`-th prime number.
644644
@@ -651,7 +651,7 @@ julia> prime(3)
651651
652652
```
653653
"""
654-
prime{T<:Integer}(::Type{T}, i::Integer) = i < 0 ? throw(DomainError(i)) : nextprime(T(2), i)
654+
prime(::Type{T}, i::Integer) where {T<:Integer} = i < 0 ? throw(DomainError(i)) : nextprime(T(2), i)
655655
prime(i::Integer) = prime(Int, i)
656656

657657
end # module

src/factorization.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# implementation of a sorted dict (not optimized for speed) for storing
22
# the factorization of an integer
33

4-
immutable Factorization{T<:Integer} <: Associative{T, Int}
4+
struct Factorization{T<:Integer} <: AbstractDict{T, Int}
55
pe::Vector{Pair{T, Int}} # Prime-Exponent
66

77
# Factorization{T}() where {T} = new(Vector{Pair{T, Int}}())
8-
(::Type{Factorization{T}}){T<:Integer}() = new{T}(Vector{Pair{T, Int}}())
8+
Factorization{T}() where {T<:Integer} = new{T}(Vector{Pair{T, Int}}())
99
end
1010

11-
function (::Type{Factorization{T}}){T<:Integer}(d::Associative)
11+
function Factorization{T}(d::AbstractDict) where T<:Integer
1212
f = Factorization{T}()
1313
append!(f.pe, sort!(collect(d)))
1414
f
1515
end
1616

17-
Base.convert{T}(::Type{Factorization}, d::Associative{T}) = Factorization{T}(d)
17+
Base.convert(::Type{Factorization}, d::AbstractDict{T}) where {T} = Factorization{T}(d)
1818

1919
Base.start(f::Factorization) = start(f.pe)
2020
Base.next(f::Factorization, i) = next(f.pe, i)
@@ -30,7 +30,7 @@ end
3030

3131
Base.getindex(f::Factorization, p::Integer) = get(f, p, 0)
3232

33-
function Base.setindex!{T}(f::Factorization{T}, e::Int, p::Integer)
33+
function Base.setindex!(f::Factorization{T}, e::Int, p::Integer) where T
3434
found = searchsorted(f.pe, p, by=first)
3535
if isempty(found)
3636
insert!(f.pe, first(found), T(p)=>e)

test/runtests.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Primes
2-
using Base.Test
2+
using Compat
3+
using Compat.Test
34
using DataStructures: SortedDict
45

56
import Primes: isprime, primes, primesmask, factor, ismersenneprime, isrieselprime, Factorization
@@ -218,7 +219,7 @@ end
218219

219220
# factor sets
220221
@test factor(Set, 100) == Set([2, 5])
221-
@test factor(IntSet, 100) == IntSet([2, 5])
222+
@test factor(BitSet, 100) == BitSet([2, 5])
222223

223224
# factor other things and fail
224225
@test_throws MethodError factor(Int, 10)
@@ -254,7 +255,7 @@ ismersenneprime(9, check=false)
254255
@test isrieselprime(3, BigInt(2)^607 - 1) # Case 2
255256
@test_throws ErrorException isrieselprime(20, 31) # Case `else`
256257

257-
# @testset "Factorization{$T} as an Associative" for T = (Int, UInt, BigInt)
258+
# @testset "Factorization{$T} as an AbstractDict" for T = (Int, UInt, BigInt)
258259
for T = (Int, UInt, BigInt)
259260
d = Dict(map(Pair, rand(T(1):T(100), 30), 1:30))
260261
f = Factorization{T}(d)
@@ -378,7 +379,7 @@ for T in (Int, UInt, BigInt)
378379
@test prodfactors(factor(C, n)) == n
379380
end
380381
if Primes.radical(n) == n
381-
for C = (Set, IntSet)
382+
for C = (Set, BitSet)
382383
@test prodfactors(factor(C, n)) == n
383384
end
384385
end

0 commit comments

Comments
 (0)