From c6fa90dbc776fc3b5d8d286376217cfa19f172e6 Mon Sep 17 00:00:00 2001 From: Lyndon White Date: Sat, 11 Jul 2020 18:51:49 +0100 Subject: [PATCH 1/2] deprecate path for partial_path --- docs/src/trie.md | 4 ++-- src/DataStructures.jl | 2 +- src/deprecations.jl | 2 ++ src/trie.jl | 2 +- test/runtests.jl | 3 ++- test/test_deprecations.jl | 17 +++++++++++++++++ test/test_trie.jl | 21 +++++++++++---------- 7 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 test/test_deprecations.jl diff --git a/docs/src/trie.md b/docs/src/trie.md index f134962ee..19a224b69 100644 --- a/docs/src/trie.md +++ b/docs/src/trie.md @@ -22,12 +22,12 @@ Trie(kvs::AbstractVector{(K, V)}) # construct a Trie from the given vector of Trie(kvs::AbstractDict{K, V}) # construct a Trie from the given associative structure ``` -This package also provides an iterator `path(t::Trie, str)` for looping +This package also provides an iterator `partial_path(t::Trie, str)` for looping over all the nodes encountered in searching for the given string `str`. This obviates much of the boilerplate code needed in writing many trie algorithms. For example, to test whether a trie contains any prefix of a given string, use: ```julia -seen_prefix(t::Trie, str) = any(v -> v.is_key, path(t, str)) +seen_prefix(t::Trie, str) = any(v -> v.is_key, partial_path(t, str)) ``` diff --git a/src/DataStructures.jl b/src/DataStructures.jl index a583b9001..a2d9b2d09 100644 --- a/src/DataStructures.jl +++ b/src/DataStructures.jl @@ -41,7 +41,7 @@ module DataStructures export heapify!, heapify, heappop!, heappush!, isheap export BinaryMinMaxHeap, popmin!, popmax!, popall! - export Trie, subtrie, keys_with_prefix, path + export Trie, subtrie, keys_with_prefix, partial_path export LinkedList, Nil, Cons, nil, cons, head, tail, list, filter, cat, reverse diff --git a/src/deprecations.jl b/src/deprecations.jl index b345bea92..3158d2093 100644 --- a/src/deprecations.jl +++ b/src/deprecations.jl @@ -6,3 +6,5 @@ export find_root const find_root = find_root! @deprecate deque(::Type{T}) where {T} Deque{T}() + +@deprecate path(t::Trie, str::AbstractString) partial_path(t::Trie, str::AbstractString) \ No newline at end of file diff --git a/src/trie.jl b/src/trie.jl index 3d55ddd96..2e54c1b60 100644 --- a/src/trie.jl +++ b/src/trie.jl @@ -120,5 +120,5 @@ function iterate(it::TrieIterator, (t, i) = (it.t, 0)) end end -path(t::Trie, str::AbstractString) = TrieIterator(t, str) +partial_path(t::Trie, str::AbstractString) = TrieIterator(t, str) Base.IteratorSize(::Type{TrieIterator}) = Base.SizeUnknown() diff --git a/test/runtests.jl b/test/runtests.jl index 0473037e0..0129f77c9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,7 +7,8 @@ import DataStructures: IntSet @test [] == detect_ambiguities(Base, Core, DataStructures) -tests = ["int_set", +tests = ["deprecations", + "int_set", "sparse_int_set", "deque", "circ_deque", diff --git a/test/test_deprecations.jl b/test/test_deprecations.jl new file mode 100644 index 000000000..9e71e9067 --- /dev/null +++ b/test/test_deprecations.jl @@ -0,0 +1,17 @@ +# These are the tests for deprecated features, they should be deleted along with them + +@testset "Trie: path iterator" begin + t = Trie{Int}() + t["rob"] = 27 + t["roger"] = 52 + t["kevin"] = Int8(11) + t0 = t + t1 = t0.children['r'] + t2 = t1.children['o'] + t3 = t2.children['b'] + @test collect(path(t, "b")) == [t0] + @test collect(path(t, "rob")) == [t0, t1, t2, t3] + @test collect(path(t, "robb")) == [t0, t1, t2, t3] + @test collect(path(t, "ro")) == [t0, t1, t2] + @test collect(path(t, "roa")) == [t0, t1, t2] +end \ No newline at end of file diff --git a/test/test_trie.jl b/test/test_trie.jl index 9cb5f658d..299a6f2ed 100644 --- a/test/test_trie.jl +++ b/test/test_trie.jl @@ -1,8 +1,6 @@ @testset "Trie" begin - - t = Trie{Int}() - @testset "Core Functionality" begin + t = Trie{Int}() t["amy"] = 56 t["ann"] = 15 t["emma"] = 30 @@ -27,16 +25,19 @@ @test isa(Trie(ks), Trie{Nothing}) end - @testset "path iterator" begin + @testset "partial_path iterator" begin + t = Trie{Int}() + t["rob"] = 27 + t["roger"] = 52 + t["kevin"] = Int8(11) t0 = t t1 = t0.children['r'] t2 = t1.children['o'] t3 = t2.children['b'] - @test collect(path(t, "b")) == [t0] - @test collect(path(t, "rob")) == [t0, t1, t2, t3] - @test collect(path(t, "robb")) == [t0, t1, t2, t3] - @test collect(path(t, "ro")) == [t0, t1, t2] - @test collect(path(t, "roa")) == [t0, t1, t2] + @test collect(partial_path(t, "b")) == [t0] + @test collect(partial_path(t, "rob")) == [t0, t1, t2, t3] + @test collect(partial_path(t, "robb")) == [t0, t1, t2, t3] + @test collect(partial_path(t, "ro")) == [t0, t1, t2] + @test collect(partial_path(t, "roa")) == [t0, t1, t2] end - end # @testset Trie From b35b3dea47bc15f101adc998fdaf18737cb53de2 Mon Sep 17 00:00:00 2001 From: Lyndon White Date: Sat, 11 Jul 2020 18:53:46 +0100 Subject: [PATCH 2/2] bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 60608952c..b92f02a99 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "DataStructures" uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" -version = "0.17.19" +version = "0.17.20" [deps] InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"