I recently came across the following implementation of a queue in an Haskell source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

dataSnocBuildera=SnocBuilder!Word[a][a]-- Smart constructor that rotates the builder when lp is one minus a power of 2sb::Word->[a]->[a]->SnocBuilderasblpfr|lp<255||(lp.&.(lp+1))/=0=SnocBuilderlpfr|otherwise=SnocBuilderlp(f++reverser)[]-- The empty builderemptySB::SnocBuilderaemptySB=SnocBuilder0[][]-- Add an element to the end of a queue.snocSB::SnocBuildera->a->SnocBuilderasnocSB(SnocBuilderlpfr)x=sb(lp+1)f(x:r)

What is the amortised running time of snocSB?

Excel in math and science

Master concepts by solving fun, challenging problems.

It's hard to learn from lectures and videos

Learn more effectively through short, conceptual quizzes.

Our wiki is made for math and science

Master advanced concepts through explanations,
examples, and problems from the community.

Used and loved by 4 million people

Learn from a vibrant community of students and enthusiasts,
including olympiad champions, researchers, and professionals.

Your answer seems reasonable.
Find out if you're right!