<s>
A	O
calendar	B-Application
queue	I-Application
(	O
CQ	O
)	O
is	O
a	O
priority	B-Application
queue	I-Application
(	O
queue	B-Application
in	O
which	O
every	O
element	O
has	O
associated	O
priority	O
and	O
the	O
dequeue	O
operation	O
removes	O
the	O
highest	O
priority	O
element	O
)	O
.	O
</s>
<s>
Discrete	B-General_Concept
event	I-General_Concept
simulations	I-General_Concept
require	O
a	O
future	O
event	O
list	O
(	O
FEL	O
)	O
structure	O
that	O
sorts	O
pending	O
events	O
according	O
to	O
their	O
time	O
.	O
</s>
<s>
Such	O
simulators	O
require	O
a	O
good	O
and	O
efficient	O
data	O
structure	O
as	O
time	O
spent	O
on	O
queue	B-Application
management	O
can	O
be	O
significant	O
.	O
</s>
<s>
The	O
calendar	B-Application
queue	I-Application
(	O
with	O
optimum	O
bucket	O
size	O
)	O
can	O
approach	O
O(1 )	O
average	O
performance	O
.	O
</s>
<s>
Calendar	B-Application
queues	I-Application
are	O
closely	O
related	O
to	O
bucket	B-Application
queues	I-Application
but	O
differ	O
from	O
them	O
in	O
how	O
they	O
are	O
searched	O
and	O
in	O
being	O
dynamically	O
resized	O
.	O
</s>
<s>
Theoretically	O
,	O
like	O
a	O
bucket	B-Application
queue	I-Application
,	O
a	O
calendar	B-Application
queue	I-Application
consists	O
of	O
an	O
array	O
of	O
linked	B-Data_Structure
lists	I-Data_Structure
.	O
</s>
<s>
The	O
bucket	O
has	O
specified	O
width	O
and	O
its	O
linked	B-Data_Structure
list	I-Data_Structure
holds	O
events	O
whose	O
timestamp	O
maps	O
to	O
that	O
bucket	O
.	O
</s>
<s>
Each	O
array	O
element	O
contains	O
one	O
pointer	O
that	O
is	O
the	O
head	O
of	O
the	O
corresponding	O
linked	B-Data_Structure
list	I-Data_Structure
.	O
</s>
<s>
The	O
complete	O
calendar	O
thus	O
consists	O
of	O
an	O
array	O
of	O
12	O
pointers	O
and	O
a	O
collection	O
of	O
up	O
to	O
12	O
linked	B-Data_Structure
lists	I-Data_Structure
.	O
</s>
<s>
In	O
calendar	B-Application
queue	I-Application
,	O
enqueue	O
(	O
addition	O
in	O
a	O
queue	B-Application
)	O
and	O
dequeue	O
(	O
deleting	O
from	O
a	O
queue	B-Application
)	O
of	O
events	O
in	O
FEL	O
is	O
based	O
on	O
event	O
time	O
.	O
</s>
<s>
Let	O
the	O
calendar	B-Application
queue	I-Application
with	O
n	O
buckets	O
with	O
w	O
width	O
.	O
</s>
<s>
To	O
dequeue	O
events	O
from	O
the	O
calendar	B-Application
queue	I-Application
,	O
it	O
keeps	O
track	O
of	O
current	O
year	O
and	O
day	O
.	O
</s>
<s>
(	O
In	O
contrast	O
,	O
a	O
bucket	B-Application
queue	I-Application
would	O
merely	O
return	O
any	O
element	O
from	O
the	O
first	O
nonempty	O
bucket	O
,	O
without	O
determining	O
which	O
element	O
in	O
that	O
bucket	O
is	O
earliest	O
.	O
)	O
</s>
<s>
If	O
the	O
number	O
of	O
events	O
in	O
the	O
queue	B-Application
is	O
much	O
smaller	O
or	O
much	O
larger	O
than	O
the	O
number	O
of	O
buckets	O
,	O
it	O
will	O
not	O
function	O
efficiently	O
.	O
</s>
<s>
The	O
solution	O
is	O
to	O
allow	O
the	O
number	O
of	O
buckets	O
to	O
correspondingly	O
grow	O
and	O
shrink	O
as	O
the	O
queue	B-Application
grows	O
and	O
shrinks	O
.	O
</s>
<s>
Thereafter	O
,	O
a	O
new	O
Calendar	B-Application
queue	I-Application
is	O
created	O
and	O
all	O
the	O
events	O
in	O
the	O
old	O
calendar	O
will	O
be	O
recopied	O
over	O
.	O
</s>
