Skip to content

Commit a60cd18

Browse files
authored
Merge pull request #644 from JuliaCollections/ox/path
deprecate path for partial_path
2 parents 6dea392 + b35b3de commit a60cd18

File tree

8 files changed

+37
-16
lines changed

8 files changed

+37
-16
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DataStructures"
22
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
3-
version = "0.17.19"
3+
version = "0.17.20"
44

55
[deps]
66
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

docs/src/trie.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ Trie(kvs::AbstractVector{(K, V)}) # construct a Trie from the given vector of
2222
Trie(kvs::AbstractDict{K, V}) # construct a Trie from the given associative structure
2323
```
2424

25-
This package also provides an iterator `path(t::Trie, str)` for looping
25+
This package also provides an iterator `partial_path(t::Trie, str)` for looping
2626
over all the nodes encountered in searching for the given string `str`.
2727
This obviates much of the boilerplate code needed in writing many trie
2828
algorithms. For example, to test whether a trie contains any prefix of a
2929
given string, use:
3030

3131
```julia
32-
seen_prefix(t::Trie, str) = any(v -> v.is_key, path(t, str))
32+
seen_prefix(t::Trie, str) = any(v -> v.is_key, partial_path(t, str))
3333
```

src/DataStructures.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module DataStructures
4141
export heapify!, heapify, heappop!, heappush!, isheap
4242
export BinaryMinMaxHeap, popmin!, popmax!, popall!
4343

44-
export Trie, subtrie, keys_with_prefix, path
44+
export Trie, subtrie, keys_with_prefix, partial_path
4545

4646
export LinkedList, Nil, Cons, nil, cons, head, tail, list, filter, cat,
4747
reverse

src/deprecations.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ export find_root
66
const find_root = find_root!
77

88
@deprecate deque(::Type{T}) where {T} Deque{T}()
9+
10+
@deprecate path(t::Trie, str::AbstractString) partial_path(t::Trie, str::AbstractString)

src/trie.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,5 @@ function iterate(it::TrieIterator, (t, i) = (it.t, 0))
120120
end
121121
end
122122

123-
path(t::Trie, str::AbstractString) = TrieIterator(t, str)
123+
partial_path(t::Trie, str::AbstractString) = TrieIterator(t, str)
124124
Base.IteratorSize(::Type{TrieIterator}) = Base.SizeUnknown()

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import DataStructures: IntSet
77

88
@test [] == detect_ambiguities(Base, Core, DataStructures)
99

10-
tests = ["int_set",
10+
tests = ["deprecations",
11+
"int_set",
1112
"sparse_int_set",
1213
"deque",
1314
"circ_deque",

test/test_deprecations.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# These are the tests for deprecated features, they should be deleted along with them
2+
3+
@testset "Trie: path iterator" begin
4+
t = Trie{Int}()
5+
t["rob"] = 27
6+
t["roger"] = 52
7+
t["kevin"] = Int8(11)
8+
t0 = t
9+
t1 = t0.children['r']
10+
t2 = t1.children['o']
11+
t3 = t2.children['b']
12+
@test collect(path(t, "b")) == [t0]
13+
@test collect(path(t, "rob")) == [t0, t1, t2, t3]
14+
@test collect(path(t, "robb")) == [t0, t1, t2, t3]
15+
@test collect(path(t, "ro")) == [t0, t1, t2]
16+
@test collect(path(t, "roa")) == [t0, t1, t2]
17+
end

test/test_trie.jl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
@testset "Trie" begin
2-
3-
t = Trie{Int}()
4-
52
@testset "Core Functionality" begin
3+
t = Trie{Int}()
64
t["amy"] = 56
75
t["ann"] = 15
86
t["emma"] = 30
@@ -27,16 +25,19 @@
2725
@test isa(Trie(ks), Trie{Nothing})
2826
end
2927

30-
@testset "path iterator" begin
28+
@testset "partial_path iterator" begin
29+
t = Trie{Int}()
30+
t["rob"] = 27
31+
t["roger"] = 52
32+
t["kevin"] = Int8(11)
3133
t0 = t
3234
t1 = t0.children['r']
3335
t2 = t1.children['o']
3436
t3 = t2.children['b']
35-
@test collect(path(t, "b")) == [t0]
36-
@test collect(path(t, "rob")) == [t0, t1, t2, t3]
37-
@test collect(path(t, "robb")) == [t0, t1, t2, t3]
38-
@test collect(path(t, "ro")) == [t0, t1, t2]
39-
@test collect(path(t, "roa")) == [t0, t1, t2]
37+
@test collect(partial_path(t, "b")) == [t0]
38+
@test collect(partial_path(t, "rob")) == [t0, t1, t2, t3]
39+
@test collect(partial_path(t, "robb")) == [t0, t1, t2, t3]
40+
@test collect(partial_path(t, "ro")) == [t0, t1, t2]
41+
@test collect(partial_path(t, "roa")) == [t0, t1, t2]
4042
end
41-
4243
end # @testset Trie

0 commit comments

Comments
 (0)