Self numbers: Difference between revisions

m
→‎generator dictionary: pqhead -> gdhead
m (→‎{{header|Phix}}: added escuse)
m (→‎generator dictionary: pqhead -> gdhead)
Line 612:
Aside: the getd_index() check is often worth trying with phix dictionaries: if there is a high probability that
the key already exists, it will yield a win, but with a low probability it will just be unhelpful overhead.
<lang Phix>integer gd = new_dict(), g = 1, pqheadgdhead = 2, n = 0
 
function ng(integer n)
Line 627:
integer nxt
n += 1
while n=pqheadgdhead do
while g<=pqheadgdhead do
nxt = ng(g)
if getd_index(nxt, gd)=NULL then -- (~25% gain)
Line 635:
g += 1
end while
integer waspqheadwasgdhead = pqheadgdhead
while true do
pqheadgdhead = pop_dict(gd)[1]
if pqheadgdhead!=waspqheadwasgdhead then exit end if
-- ?{"ding",waspqheadwasgdhead} -- 2, once only...
end while
nxt = ng(pqheadgdhead)
-- if getd_index(nxt, gd)=NULL then -- (~1% loss)
setd(nxt,0,gd)
-- end if
n += (n!=pqheadgdhead)
end while
return n
7,820

edits