From 68d53c01b0b8e9a007a6a30158c19e34b2d2a34e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Wed, 18 May 2016 15:53:35 +0200 Subject: Update STDLIB documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Language cleaned up by the technical writers xsipewe and tmanevik from Combitech. Proofreading and corrections by Björn Gustavsson and Hans Bolinder. --- lib/stdlib/doc/src/queue.xml | 354 ++++++++++++++++++++++++++----------------- 1 file changed, 212 insertions(+), 142 deletions(-) (limited to 'lib/stdlib/doc/src/queue.xml') diff --git a/lib/stdlib/doc/src/queue.xml b/lib/stdlib/doc/src/queue.xml index e1a96f5c65..a46ca47033 100644 --- a/lib/stdlib/doc/src/queue.xml +++ b/lib/stdlib/doc/src/queue.xml @@ -28,63 +28,74 @@ 1 Bjarne Däcker - 97-01-15 + 1997-01-15 B - queue.sgml + queue.xml queue - Abstract Data Type for FIFO Queues + Abstract data type for FIFO queues. -

This module implements (double ended) FIFO queues +

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, list arguments are + 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 - should be regarded as opaque by other modules. Any code + is to be regarded as opaque by other modules. Any code assuming knowledge of the format is running on thin ice.

+

All operations has an amortized O(1) running time, except - len/1, join/2, split/2, filter/2 - and member/2 that have O(n). + filter/2, + 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 + +

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.

-

The module has several sets of interface functions. The - "Original API", the "Extended API" and the "Okasaki API".

+ +

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 also + 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" contain alternative functions that build - less garbage as well as functions for just inspecting the + 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" + +

The "Okasaki API" is inspired by "Purely Functional Data Structures" by Chris Okasaki. It regards queues as lists. - The API is by many regarded as strange and avoidable. - For example many reverse operations have lexically reversed names, + 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.

- -
Original API
@@ -92,7 +103,8 @@ -

As returned by new/0.

+

As returned by + new/0.

@@ -101,205 +113,229 @@ - - Create an empty queue + + Filter a queue. -

Returns an empty queue.

+

Returns a queue Q2 that is the result of calling + Fun(Item) on all items in + Q1, in order from front to rear.

+

If Fun(Item) returns true, + Item is copied to the result queue. If it returns false, + Item is not copied. If it returns a list, + the list elements are inserted instead of Item in the + result queue.

+

So, Fun(Item) returning + [Item] is thereby + semantically equivalent to returning true, just + as returning [] is semantically equivalent to + returning false. But returning a list builds + more garbage than returning an atom.

+ - - Test if a term is a queue + + Convert a list to a queue. -

Tests if Term is a queue and returns true if so and - false otherwise.

+

Returns a queue containing the items in L in the + same order; the head item of the list becomes the front + item of the queue.

+ - - Test if a queue is empty + + Insert an item at the rear of a queue. -

Tests if Q is empty and returns true if so and - false otherwise.

+

Inserts Item at the rear of queue + Q1. + Returns the resulting queue Q2.

+ - - Get the length of a queue + + Insert an item at the front of a queue. -

Calculates and returns the length of queue Q.

+

Inserts Item at the front of queue + Q1. + Returns the resulting queue Q2.

- - Insert an item at the rear of a queue + + Test if a queue is empty. -

Inserts Item at the rear of queue Q1. - Returns the resulting queue Q2.

+

Tests if Q is empty and returns true if + so, otherwise otherwise.

+ - - Insert an item at the front of a queue + + Test if a term is a queue. -

Inserts Item at the front of queue Q1. - Returns the resulting queue Q2.

+

Tests if Term is a queue and returns true + if so, otherwise false.

+ - - Remove the front item from a queue + + Join two queues. -

Removes the item at the front of queue Q1. Returns the - tuple {{value, Item}, Q2}, where Item is the - item removed and Q2 is the resulting queue. If Q1 is - empty, the tuple {empty, Q1} is returned.

+

Returns a queue Q3 that is the result of joining + Q1 and Q2 with + Q1 in front of Q2.

+ - - Remove the rear item from a queue + + Get the length of a queue. -

Removes the item at the rear of the queue Q1. Returns the - tuple {{value, Item}, Q2}, where Item is the - item removed and Q2 is the new queue. If Q1 is - empty, the tuple {empty, Q1} is returned.

+

Calculates and returns the length of queue Q.

- - Convert a list to a queue + + Test if an item is in a queue. -

Returns a queue containing the items in L in the - same order; the head item of the list will become the front - item of the queue.

+

Returns true if Item matches some element + in Q, otherwise false.

+ - - Convert a queue to a list + + Create an empty queue. -

Returns a list of the items in the queue in the same order; - the front item of the queue will become the head of the list.

+

Returns an empty queue.

- - Reverse a queue + + Remove the front item from a queue. -

Returns a queue Q2 that contains the items of - Q1 in the reverse order.

+

Removes the item at the front of queue Q1. + Returns tuple {{value, Item}, Q2}, + where Item is the item removed and + Q2 is the resulting queue. If + Q1 is empty, tuple + {empty, Q1} is returned.

+ - - Split a queue in two + + Remove the rear item from a queue. -

Splits Q1 in two. The N front items - are put in Q2 and the rest in Q3

+

Removes the item at the rear of queue Q1. + Returns tuple {{value, Item}, Q2}, + where Item is the item removed and + Q2 is the new queue. If Q1 is + empty, tuple {empty, Q1} is returned.

+ - - Join two queues + + Reverse a queue. -

Returns a queue Q3 that is the result of joining - Q1 and Q2 with Q1 in front of - Q2.

+

Returns a queue Q2 containing the items of + Q1 in the reverse order.

+ - - Filter a queue + + Split a queue in two. -

Returns a queue Q2 that is the result of calling - Fun(Item) on all items in Q1, - in order from front to rear.

-

If Fun(Item) returns true, Item - is copied to the result queue. If it returns false, - Item is not copied. If it returns a list - the list elements are inserted instead of Item in the - result queue.

-

So, Fun(Item) returning [Item] is thereby - semantically equivalent to returning true, just - as returning [] is semantically equivalent to - returning false. But returning a list builds - more garbage than returning an atom.

+

Splits Q1 in two. The N + front items are put in Q2 and the rest in + Q3.

+ - - Test if an item is in a queue + + Convert a queue to a list. -

Returns true if Item matches some element - in Q, otherwise false.

+

Returns a list of the items in the queue in the same order; + the front item of the queue becomes the head of the list.

- -
Extended API
- - - Return the front item of a queue - -

Returns Item at the front of queue Q.

-

Fails with reason empty if Q is empty.

-
-
- - - Return the rear item of a queue - -

Returns Item at the rear of queue Q.

-

Fails with reason empty if Q is empty.

-
-
- Remove the front item from a queue + Remove the front item from a queue.

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

Fails with reason empty if Q1 is empty.

+ - Remove the rear item from a queue + Remove the rear item from a queue.

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

Fails with reason empty if Q1 is empty.

+ + + + Return the front item of a queue. + +

Returns Item at the front of queue + Q.

+

Fails with reason empty if Q is empty.

+
+
+ + + + Return the rear item of a queue. + +

Returns Item at the rear of queue + Q.

+

Fails with reason empty if Q is empty.

+
+
+ - Return the front item of a queue + Return the front item of a queue. -

Returns the tuple {value, Item} where Item is the - front item of Q, or empty if Q is empty.

+

Returns tuple {value, Item}, where + Item is the front item of Q, + or empty if Q is empty.

+ - Return the rear item of a queue + Return the rear item of a queue. -

Returns the tuple {value, Item} where Item is the - rear item of Q, or empty if Q is empty.

+

Returns tuple {value, Item}, where + Item is the rear item of Q, + or empty if Q is empty.

-
Okasaki API
@@ -307,58 +343,92 @@ - Insert an item at the head of a queue + Insert an item at the head of a queue. -

Inserts Item at the head of queue Q1. Returns +

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

+ + + + Return the tail item of a queue. + +

Returns the tail item of queue Q.

+

Fails with reason empty if Q is empty.

+
+
+ - Return the item at the head of a queue + Return the item at the head of a queue. -

Returns Item from the head of queue Q.

+

Returns Item from the head of queue + Q.

Fails with reason empty if Q is empty.

+ - - Remove the head item from a queue + + Remove the tail item from a queue.

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

+ the tail item from Q1.

Fails with reason empty if Q1 is empty.

+ - - Insert an item at the tail of a queue + + Remove the tail item from a queue. -

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

+

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.

+ - - Return the tail item of a queue + Return the tail item of a queue.

Returns the tail item of queue Q.

Fails with reason empty if Q is empty.

+ - - - - Remove the tail item from a queue + v + Remove the tail item from a queue.

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.

-
+ + + Insert an item at the tail of a queue. + +

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

+
+
+ + + + Remove the head item from a queue. + +

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

+

Fails with reason empty if Q1 is empty.

+
+
+ + -- cgit v1.2.3