Skip to content

Commit

Permalink
Merge pull request JuliaLang#14530 from hayd/rst
Browse files Browse the repository at this point in the history
Remove last rst docstrings
  • Loading branch information
hayd committed Jan 2, 2016
2 parents 31b04bd + 86e6d7f commit ed85e3b
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 105 deletions.
58 changes: 51 additions & 7 deletions base/collections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ end

percolate_up!{T}(xs::AbstractArray{T}, i::Integer, o::Ordering) = percolate_up!(xs, i, xs[i], o)

"""
heappop!(v, [ord])
# Binary min-heap pop.
Given a binary heap-ordered array, remove and return the lowest ordered element.
For efficiency, this function does not check that the array is indeed heap-ordered.
"""
function heappop!(xs::AbstractArray, o::Ordering=Forward)
x = xs[1]
y = pop!(xs)
Expand All @@ -72,8 +76,12 @@ function heappop!(xs::AbstractArray, o::Ordering=Forward)
x
end

"""
heappush!(v, x, [ord])
# Binary min-heap push.
Given a binary heap-ordered array, push a new element `x`, preserving the heap property.
For efficiency, this function does not check that the array is indeed heap-ordered.
"""
function heappush!(xs::AbstractArray, x, o::Ordering=Forward)
push!(xs, x)
percolate_up!(xs, length(xs), x, o)
Expand All @@ -82,17 +90,30 @@ end


# Turn an arbitrary array into a binary min-heap in linear time.
"""
heapify!(v, [ord])
In-place [`heapify`](:func:`heapify`).
"""
function heapify!(xs::AbstractArray, o::Ordering=Forward)
for i in heapparent(length(xs)):-1:1
percolate_down!(xs, i, o)
end
xs
end

"""
heapify(v, [ord])
Returns a new vector in binary heap order, optionally using the given ordering.
"""
heapify(xs::AbstractArray, o::Ordering=Forward) = heapify!(copy(xs), o)

"""
isheap(v, [ord])
# Is an arbitrary array heap ordered?
Return `true` if an array is heap-ordered according to the given order.
"""
function isheap(xs::AbstractArray, o::Ordering=Forward)
for i in 1:div(length(xs), 2)
if lt(o, xs[heapleft(i)], xs[i]) ||
Expand All @@ -107,9 +128,18 @@ end
# PriorityQueue
# -------------

# A PriorityQueue that acts like a Dict, mapping values to their priorities,
# with the addition of a dequeue! function to remove the lowest priority
# element.
"""
PriorityQueue(K, V, [ord])
Construct a new [`PriorityQueue`](:obj:`PriorityQueue`), with keys of type
`K` and values/priorites of type `V`.
If an order is not given, the priority queue is min-ordered using
the default comparison for `V`.
A `PriorityQueue` acts like a `Dict`, mapping values to their
priorities, with the addition of a `dequeue!` function to remove the
lowest priority element.
"""
type PriorityQueue{K,V,O<:Ordering} <: Associative{K,V}
# Binary heap of (element, priority) pairs.
xs::Array{Pair{K,V}, 1}
Expand Down Expand Up @@ -168,8 +198,14 @@ PriorityQueue{K,V}(a::AbstractArray{Tuple{K,V}}, o::Ordering=Forward) = Priority
length(pq::PriorityQueue) = length(pq.xs)
isempty(pq::PriorityQueue) = isempty(pq.xs)
haskey(pq::PriorityQueue, key) = haskey(pq.index, key)
peek(pq::PriorityQueue) = pq.xs[1]

"""
peek(pq)
Return the lowest priority key from a priority queue without removing that
key from the queue.
"""
peek(pq::PriorityQueue) = pq.xs[1]

function percolate_down!(pq::PriorityQueue, i::Integer)
x = pq.xs[i]
Expand Down Expand Up @@ -246,7 +282,11 @@ function setindex!{K,V}(pq::PriorityQueue{K, V}, value, key)
value
end

"""
enqueue!(pq, k, v)
Insert the a key `k` into a priority queue `pq` with priority `v`.
"""
function enqueue!{K,V}(pq::PriorityQueue{K,V}, key, value)
if haskey(pq, key)
throw(ArgumentError("PriorityQueue keys must be unique"))
Expand All @@ -257,7 +297,11 @@ function enqueue!{K,V}(pq::PriorityQueue{K,V}, key, value)
pq
end

"""
dequeue!(pq)
Remove and return the lowest priority key from a priority queue.
"""
function dequeue!(pq::PriorityQueue)
x = pq.xs[1]
y = pop!(pq.xs)
Expand Down
1 change: 0 additions & 1 deletion base/docs/helpdb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import .Docs: keywords
include("helpdb/BLAS.jl")
include("helpdb/Libdl.jl")
include("helpdb/Libc.jl")
include("helpdb/Collections.jl")
include("helpdb/Profile.jl")
include("helpdb/Base.jl")
include("helpdb/Dates.jl")
2 changes: 1 addition & 1 deletion base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9928,7 +9928,7 @@ isvalid(::AbstractString,i)
esc(e::ANY)
Only valid in the context of an `Expr` returned from a macro. Prevents the macro hygiene
pass from turning embedded variables into gensym variables. See the [marcro](:ref:`man-macros`)
pass from turning embedded variables into gensym variables. See the [macro](:ref:`man-macros`)
section of the Metaprogramming chapter of the manual for more details and examples.
"""
esc
Expand Down
74 changes: 0 additions & 74 deletions base/docs/helpdb/Collections.jl

This file was deleted.

15 changes: 6 additions & 9 deletions base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -446,17 +446,14 @@ function sprand_IJ(r::AbstractRNG, m::Integer, n::Integer, density::AbstractFloa
end

"""
```rst
.. sprand([rng],m,[n],p::AbstractFloat,[rfn])
sprand([rng],m,[n],p::AbstractFloat,[rfn])
Create a random length ``m`` sparse vector or ``m`` by ``n`` sparse matrix, in
Create a random length `m` sparse vector or `m` by `n` sparse matrix, in
which the probability of any element being nonzero is independently given by
``p`` (and hence the mean density of nonzeros is also exactly ``p``). Nonzero
values are sampled from the distribution specified by ``rfn``. The uniform
distribution is used in case ``rfn`` is not specified. The optional ``rng``
argument specifies a random number generator, see :ref:`Random Numbers
<random-numbers>`.
```
`p` (and hence the mean density of nonzeros is also exactly `p`). Nonzero
values are sampled from the distribution specified by `rfn`. The uniform
distribution is used in case `rfn` is not specified. The optional `rng`
argument specifies a random number generator, see [Random Numbers](:ref:`Random Numbers <random-numbers>`).
"""
function sprand{T}(r::AbstractRNG, m::Integer, n::Integer, density::AbstractFloat,
rfn::Function, ::Type{T}=eltype(rfn(r,1)))
Expand Down
8 changes: 1 addition & 7 deletions doc/stdlib/arrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -925,13 +925,7 @@ dense counterparts. The following functions are specific to sparse arrays.

.. Docstring generated from Julia source
Create a random length ``m`` sparse vector or ``m`` by ``n`` sparse matrix, in
which the probability of any element being nonzero is independently given by
``p`` (and hence the mean density of nonzeros is also exactly ``p``). Nonzero
values are sampled from the distribution specified by ``rfn``. The uniform
distribution is used in case ``rfn`` is not specified. The optional ``rng``
argument specifies a random number generator, see :ref:`Random Numbers
<random-numbers>`.
Create a random length ``m`` sparse vector or ``m`` by ``n`` sparse matrix, in which the probability of any element being nonzero is independently given by ``p`` (and hence the mean density of nonzeros is also exactly ``p``\ ). Nonzero values are sampled from the distribution specified by ``rfn``\ . The uniform distribution is used in case ``rfn`` is not specified. The optional ``rng`` argument specifies a random number generator, see :ref:`Random Numbers <random-numbers>`\ .

.. function:: sprandn(m[,n],p::AbstractFloat)

Expand Down
12 changes: 6 additions & 6 deletions doc/stdlib/collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1287,9 +1287,9 @@ changed efficiently.

.. Docstring generated from Julia source
Construct a new :obj:`PriorityQueue`, with keys of type ``K`` and values/priorites of
type ``V``. If an order is not given, the priority queue is min-ordered using
the default comparison for ``V``.
Construct a new :obj:`PriorityQueue`\ , with keys of type ``K`` and values/priorites of type ``V``\ . If an order is not given, the priority queue is min-ordered using the default comparison for ``V``\ .

A ``PriorityQueue`` acts like a ``Dict``\ , mapping values to their priorities, with the addition of a ``dequeue!`` function to remove the lowest priority element.

.. function:: enqueue!(pq, k, v)

Expand Down Expand Up @@ -1343,19 +1343,19 @@ is used, so that elements popped from the heap are given in ascending order.

.. Docstring generated from Julia source
Return a new vector in binary heap order, optionally using the given ordering.
Returns a new vector in binary heap order, optionally using the given ordering.

.. function:: heapify!(v, [ord])

.. Docstring generated from Julia source
In-place :func:`heapify`.
In-place :func:`heapify`\ .

.. function:: isheap(v, [ord])

.. Docstring generated from Julia source
Return ``true`` iff an array is heap-ordered according to the given order.
Return ``true`` if an array is heap-ordered according to the given order.

.. function:: heappush!(v, x, [ord])

Expand Down

0 comments on commit ed85e3b

Please sign in to comment.