logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

queue - Abstract data type for FIFO queues.

Data Types

queue(Item)

              As returned by new/0.

       queue() = queue(term())

Description

       This module provides (double-ended) FIFO queues in an efficient manner.

       All  functions  fail  with reason badarg if arguments are of wrong type, for example, queue arguments are
       not queues, indexes are not integers, and list arguments are not lists.  Improper  lists  cause  internal
       crashes. An index out of range for a queue also causes a failure with reason badarg.

       Some functions, where noted, fail with reason empty for an empty queue.

       The  data  representing  a queue as used by this module is to be regarded as opaque by other modules. Any
       code assuming knowledge of the format is running on thin ice.

       All operations  have  an  amortized  O(1)  running  time,  except  all/2,  any/2,  delete/2,  delete_r/2,
       delete_with/2, delete_with_r/2, filter/2, filtermap/2, fold/3, join/2, len/1, member/2, split/2 that have
       O(n).  To  minimize  the  size of a queue minimizing the amount of garbage built by queue operations, the
       queues do not contain explicit length information, and that is why len/1 is O(n). If  better  performance
       for this particular operation is essential, it is easy for the caller to keep track of the length.

       Queues  are  double-ended.  The  mental  picture of a queue is a line of people (items) waiting for their
       turn. The queue front is the end with the item that has waited the longest. The queue rear is the end  an
       item  enters  when  it starts to wait. If instead using the mental picture of a list, the front is called
       head and the rear is called tail.

       Entering at the front and exiting at the rear are reverse operations on the queue.

       This module has three sets of interface functions: the  "Original  API",  the  "Extended  API",  and  the
       "Okasaki API".

       The  "Original  API"  and the "Extended API" both use the mental picture of a waiting line of items. Both
       have reverse operations suffixed "_r".

       The "Original API" item removal functions return compound terms  with  both  the  removed  item  and  the
       resulting  queue. The "Extended API" contains alternative functions that build less garbage and functions
       for just inspecting the queue ends. Also the "Okasaki API" functions build less garbage.

       The "Okasaki API" is inspired by "Purely Functional Data Structures" by Chris Okasaki. It regards  queues
       as  lists.  This  API  is by many regarded as strange and avoidable. For example, many reverse operations
       have lexically reversed names, some with more readable but perhaps less understandable aliases.

Exports

cons(Item,Q1::queue(Item))->Q2::queue(Item)

              Inserts Item at the head of queue Q1. Returns the new queue Q2.

       daeh(Q::queue(Item))->Item

              Returns the tail item of queue Q.

              Fails with reason empty if Q is empty.

       head(Q::queue(Item))->Item

              Returns Item from the head of queue Q.

              Fails with reason empty if Q is empty.

       init(Q1::queue(Item))->Q2::queue(Item)

              Returns a queue Q2 that is the result of removing the tail item from Q1.

              Fails with reason empty if Q1 is empty.

       lait(Q1::queue(Item))->Q2::queue(Item)

              Returns a queue Q2 that is the result of removing the tail item from Q1.

              Fails with reason empty if Q1 is empty.

              The name lait/1 is a misspelling - do not use it anymore.

       last(Q::queue(Item))->Item

              Returns the tail item of queue Q.

              Fails with reason empty if Q is empty.

       liat(Q1::queue(Item))->Q2::queue(Item)

              Returns a queue Q2 that is the result of removing the tail item from Q1.

              Fails with reason empty if Q1 is empty.

       snoc(Q1::queue(Item),Item)->Q2::queue(Item)

              Inserts Item as the tail item of queue Q1. Returns the new queue Q2.

       tail(Q1::queue(Item))->Q2::queue(Item)

              Returns a queue Q2 that is the result of removing the head item from Q1.

              Fails with reason empty if Q1 is empty.

Ericsson AB                                        stdlib 3.17                                       queue(3erl)

Extended Api

Name

       queue - Abstract data type for FIFO queues.

Okasaki Api

Original Api

See Also