Skip to content

Commit 6c413c4

Browse files
committed
subtrees of Hubbard trees by indexing with strings
1 parent 61e3bae commit 6c413c4

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

sequences/Sequences.jl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ function ==(x::Sequence,y::Sequence)
4646
end
4747

4848
function Base.getindex(S::Sequence, ii::Int)
49-
k = length(S.items) - S.preperiod
50-
return S.items[mod1(ii-S.preperiod,k)]
49+
if ii <= S.preperiod
50+
return S.items[ii]
51+
else
52+
k = length(S.items) - S.preperiod
53+
return S.items[mod1(ii-S.preperiod,k)]
54+
end
5155
end
5256

5357
function Base.getindex(S::Sequence, I::UnitRange)
@@ -127,6 +131,16 @@ function divisors(n)
127131
return sort(d)
128132
end
129133

134+
function agrees(K::Sequence,str::String)
135+
for (ii,item) in enumerate(str)
136+
if item !== K[ii]
137+
return false
138+
end
139+
end
140+
return true
141+
end
130142

131-
143+
function prepend(K::Sequence,thing)
144+
return Sequence{Char}(pushfirst!(copy(K.items),thing),K.preperiod+1)
145+
end
132146

trees/HubbardTrees.jl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,28 @@ abstract type AbstractHubbardTree
99
end
1010

1111
struct HubbardTree <: AbstractHubbardTree
12-
zero::Sequence
12+
zero::Sequence #Rename this to critical? Remove it and use H["*"] everywhere?
1313
adj::Dict{Sequence,Set{Sequence}}
1414
end
1515

16+
function Base.getindex(H::HubbardTree, str::String)
17+
list = []
18+
for (K,neighbors) in pairs(H.adj)
19+
if agrees(K,str)
20+
newneighbors = []
21+
for N in neighbors
22+
if agrees(N,str)
23+
push!(newneighbors,N)
24+
end
25+
end
26+
push!(list,Pair(K,newneighbors))
27+
end
28+
end
29+
return Dict(list)
30+
end
31+
1632
function HubbardTree(K::Sequence{Char})
17-
starK = Sequence{Char}(pushfirst!(copy(K.items),'*'),K.preperiod+1)
33+
starK = prepend(K,'*')
1834
#We begin with the critical orbit
1935
markedpoints = copy(orbit(starK).items)
2036

0 commit comments

Comments
 (0)