home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / bbs / gnu / libg++-2.5.3-bin.lha / info / libg++.info-4 < prev    next >
Encoding:
GNU Info File  |  1994-02-27  |  49.9 KB  |  1,579 lines

  1. This is Info file libg++.info, produced by Makeinfo-1.55 from the input
  2. file ./libg++.texi.
  3.  
  4. START-INFO-DIR-ENTRY
  5. * Libg++::                      The g++ class library.
  6. END-INFO-DIR-ENTRY
  7.  
  8.    This file documents the features and implementation of The GNU C++
  9. library
  10.  
  11.    Copyright (C) 1988, 1991, 1992 Free Software Foundation, Inc.
  12.  
  13.    Permission is granted to make and distribute verbatim copies of this
  14. manual provided the copyright notice and this permission notice are
  15. preserved on all copies.
  16.  
  17.    Permission is granted to copy and distribute modified versions of
  18. this manual under the conditions for verbatim copying, provided also
  19. that the section entitled "GNU Library General Public License" is
  20. included exactly as in the original, and provided that the entire
  21. resulting derived work is distributed under the terms of a permission
  22. notice identical to this one.
  23.  
  24.    Permission is granted to copy and distribute translations of this
  25. manual into another language, under the above conditions for modified
  26. versions, except that the section entitled "GNU Library General Public
  27. License" and this permission notice may be included in translations
  28. approved by the Free Software Foundation instead of in the original
  29. English.
  30.  
  31. 
  32. File: libg++.info,  Node: Data,  Next: Curses,  Prev: Random,  Up: Top
  33.  
  34. Data Collection
  35. ***************
  36.  
  37.    Libg++ currently provides two classes for *data collection* and
  38. analysis of the collected data.
  39.  
  40. SampleStatistic
  41. ===============
  42.  
  43.    Class `SampleStatistic' provides a means of accumulating samples of
  44. `double' values and providing common sample statistics.
  45.  
  46.    Assume declaration of `double x'.
  47.  
  48. `SampleStatistic a;'
  49.      declares and initializes a.
  50.  
  51. `a.reset();'
  52.      re-initializes a.
  53.  
  54. `a += x;'
  55.      adds sample x.
  56.  
  57. `int n = a.samples();'
  58.      returns the number of samples.
  59.  
  60. `x = a.mean;'
  61.      returns the means of the samples.
  62.  
  63. `x = a.var()'
  64.      returns the sample variance of the samples.
  65.  
  66. `x = a.stdDev()'
  67.      returns the sample standard deviation of the samples.
  68.  
  69. `x = a.min()'
  70.      returns the minimum encountered sample.
  71.  
  72. `x = a.max()'
  73.      returns the maximum encountered sample.
  74.  
  75. `x = a.confidence(int p)'
  76.      returns the p-percent (0 <= p < 100) confidence interval.
  77.  
  78. `x = a.confidence(double p)'
  79.      returns the p-probability (0 <= p < 1) confidence interval.
  80.  
  81. SampleHistogram
  82. ===============
  83.  
  84.    Class `SampleHistogram' is a derived class of `SampleStatistic' that
  85. supports collection and display of samples in bucketed intervals. It
  86. supports the following in addition to `SampleStatisic' operations.
  87.  
  88. `SampleHistogram h(double lo, double hi, double width);'
  89.      declares and initializes h to have buckets of size width from lo
  90.      to hi.  If the optional argument width is not specified, 10
  91.      buckets are created. The first bucket and also holds samples less
  92.      than lo, and the last one holds samples greater than hi.
  93.  
  94. `int n = h.similarSamples(x)'
  95.      returns the number of samples in the same bucket as x.
  96.  
  97. `int n = h.inBucket(int i)'
  98.      returns the number of samples in  bucket i.
  99.  
  100. `int b = h.buckets()'
  101.      returns the number of buckets.
  102.  
  103. `h.printBuckets(ostream s)'
  104.      prints bucket counts on ostream s.
  105.  
  106. `double bound = h.bucketThreshold(int i)'
  107.      returns the upper bound of bucket i.
  108.  
  109. 
  110. File: libg++.info,  Node: Curses,  Next: List,  Prev: Data,  Up: Top
  111.  
  112. Curses-based classes
  113. ********************
  114.  
  115.    The `CursesWindow' class is a repackaging of standard curses library
  116. features into a class. It relies on `curses.h'.
  117.  
  118.    The supplied `curses.h' is a fairly conservative declaration of
  119. curses library features, and does not include features like "screen" or
  120. X-window support. It is, for the most part, an adaptation, rather than
  121. an improvement of C-based `curses.h' files. The only substantive
  122. changes are the declarations of many functions as inline functions
  123. rather than macros, which was done solely to allow overloading.
  124.  
  125.    The `CursesWindow' class encapsulates curses window functions within
  126. a class. Only those functions that control windows are included:
  127. Terminal control functions and macros like `cbreak' are not part of the
  128. class.  All `CursesWindows' member functions have names identical to
  129. the corresponding curses library functions, except that the "w" prefix
  130. is generally dropped. Descriptions of these functions may be found in
  131. your local curses library documentation.
  132.  
  133.    A `CursesWindow' may be declared via
  134.  
  135. `CursesWindow w(WINDOW* win)'
  136.      attaches w to the existing WINDOW* win. This is constructor is
  137.      normally used only in the following special case.
  138.  
  139. `CursesWindow w(stdscr)'
  140.      attaches w to the default curses library standard screen window.
  141.  
  142. `CursesWindow w(int lines, int cols, int begin_y, int begin_x)'
  143.      attaches to an allocated curses window with the indicated size and
  144.      screen position.
  145.  
  146. `CursesWindow sub(CursesWindow& w,int l,int c,int by,int bx,char ar='a')'
  147.      attaches to a subwindow of w created via the curses `subwin'
  148.      command.  If ar is sent as `r', the origin (by, bx) is relative to
  149.      the parent window, else it is absolute.
  150.  
  151.    The class maintains a static counter that is used in order to
  152. automatically call the curses library `initscr' and `endscr' functions
  153. at the proper times. These need not, and should not be called
  154. "manually".
  155.  
  156.    `CursesWindow's maintain a tree of their subwindows. Upon
  157. destruction of a `CursesWindow', all of their subwindows are also
  158. invalidated if they had not previously been destroyed.
  159.  
  160.    It is possible to traverse trees of subwindows via the following
  161. member functions
  162.  
  163. `CursesWindow* w.parent()'
  164.      returns a pointer to the parent of the subwindow, or 0 if there is
  165.      none.
  166.  
  167. `CursesWindow* w.child()'
  168.      returns the first child subwindow of the window, or 0 if there is
  169.      none.
  170.  
  171. `CursesWindow* w.sibling()'
  172.      returns the next sibling of the subwindow, or 0 if there is none.
  173.  
  174.    For example, to call some function `visit' for all subwindows of a
  175. window, you could write
  176.  
  177.  
  178.      void traverse(CursesWindow& w)
  179.      {
  180.        visit(w);
  181.        if (w.child() != 0) traverse(*w.child);
  182.        if (w.sibling() != 0) traverse(*w.sibling);
  183.      }
  184.  
  185. 
  186. File: libg++.info,  Node: List,  Next: LinkList,  Prev: Curses,  Up: Top
  187.  
  188. List classes
  189. ************
  190.  
  191.    The files `g++-include/List.hP' and `g++-include/List.ccP' provide
  192. pseudo-generic Lisp-type List classes.  These lists are homogeneous
  193. lists, more similar to lists in statically typed functional languages
  194. like ML than Lisp, but support operations very similar to those found
  195. in Lisp.  Any particular kind of list class may be generated via the
  196. `genclass' shell command. However, the implementation assumes that the
  197. base class supports an equality operator `=='.  All equality tests use
  198. the `==' operator, and are thus equivalent to the use of `equal', not
  199. `eq' in Lisp.
  200.  
  201.    All list nodes are created dynamically, and managed via reference
  202. counts.  `List' variables are actually pointers to these list nodes.
  203. Lists may also be traversed via Pixes, as described in the section
  204. describing Pixes. *Note Pix::
  205.  
  206.    Supported operations are mirrored closely after those in Lisp.
  207. Generally, operations with functional forms are constructive,
  208. functional operations, while member forms (often with the same name)
  209. are sometimes procedural, possibly destructive operations.
  210.  
  211.    As with Lisp, destructive operations are supported. Programmers are
  212. allowed to change head and tail fields in any fashion, creating
  213. circular structures and the like. However, again as with Lisp, some
  214. operations implicitly assume that they are operating on pure lists, and
  215. may enter infinite loops when presented with improper lists. Also, the
  216. reference-counting storage management facility may fail to reclaim
  217. unused circularly-linked nodes.
  218.  
  219.    Several Lisp-like higher order functions are supported (e.g., `map').
  220. Typedef declarations for the required functional forms are provided int
  221. the `.h' file.
  222.  
  223.    For purposes of illustration, assume the specification of class
  224. `intList'.  Common Lisp versions of supported operations are shown in
  225. brackets for comparison purposes.
  226.  
  227. Constructors and assignment
  228. ===========================
  229.  
  230. `intList a;           [ (setq a nil) ]'
  231.      Declares a to be a nil intList.
  232.  
  233. `intList b(2);        [ (setq b (cons 2 nil)) ]'
  234.      Declares b to be an intList with a head value of 2, and a nil tail.
  235.  
  236. `intList c(3, b);     [ (setq c (cons 3 b)) ]'
  237.      Declares c to be an intList with a head value of 3, and b as its
  238.      tail.
  239.  
  240. `b = a;               [ (setq b a) ]'
  241.      Sets b to be the same list as a.
  242.  
  243.    Assume the declarations of intLists a, b, and c in the following.
  244. *Note Pix::.
  245.  
  246. List status
  247. ===========
  248.  
  249. `a.null(); OR !a;      [ (null a) ]'
  250.      returns true if a is null.
  251.  
  252. `a.valid();            [ (listp a) ]'
  253.      returns true if a is non-null. Inside a conditional test, the
  254.      `void*' coercion may also be used as in `if (a) ...'.
  255.  
  256. `intList();            [ nil ]'
  257.      intList() may be used to null terminate a list, as in `intList
  258.      f(int x) {if (x == 0) return intList(); ... } '.
  259.  
  260. `a.length();           [ (length a) ]'
  261.      returns the length of a.
  262.  
  263. `a.list_length();      [ (list-length a) ]'
  264.      returns the length of a, or -1 if a is circular.
  265.  
  266. heads and tails
  267. ===============
  268.  
  269. `a.get(); OR a.head()  [ (car a) ]'
  270.      returns a reference to the head field.
  271.  
  272. `a[2];                 [ (elt a 2) ]'
  273.      returns a reference to the second (counting from zero) head field.
  274.  
  275. `a.tail();             [ (cdr a) ]'
  276.      returns the intList that is the tail of a.
  277.  
  278. `a.last();             [ (last a) ]'
  279.      returns the intList that is the last node of a.
  280.  
  281. `a.nth(2);             [ (nth a 2) ]'
  282.      returns the intList that is the nth node of a.
  283.  
  284. `a.set_tail(b);        [ (rplacd a b) ]'
  285.      sets a's tail to b.
  286.  
  287. `a.push(2);            [ (push 2 a) ]'
  288.      equivalent to a = intList(2, a);
  289.  
  290. `int x = a.pop()       [ (setq x (car a)) (pop a) ]'
  291.      returns the head of a, also setting a to its tail.
  292.  
  293. Constructive operations
  294. =======================
  295.  
  296. `b = copy(a);          [ (setq b (copy-seq a)) ]'
  297.      sets b to a copy of a.
  298.  
  299. `b = reverse(a);       [ (setq b (reverse a)) ]'
  300.      Sets b to a reversed copy of a.
  301.  
  302. `c = concat(a, b);     [ (setq c (concat a b)) ]'
  303.      Sets c to a concatenated copy of a and b.
  304.  
  305. `c = append(a, b);     [ (setq c (append a b)) ]'
  306.      Sets c to a concatenated copy of a and b. All nodes of a are
  307.      copied, with the last node pointing to b.
  308.  
  309. `b = map(f, a);        [ (setq b (mapcar f a)) ]'
  310.      Sets b to a new list created by applying function f to each node
  311.      of a.
  312.  
  313. `c = combine(f, a, b);'
  314.      Sets c to a new list created by applying function f to successive
  315.      pairs of a and b. The resulting list has length the shorter of a
  316.      and b.
  317.  
  318. `b = remove(x, a);     [ (setq b (remove x a)) ]'
  319.      Sets b to a copy of a, omitting all occurrences of x.
  320.  
  321. `b = remove(f, a);     [ (setq b (remove-if f a)) ]'
  322.      Sets b to a copy of a, omitting values causing function f to
  323.      return true.
  324.  
  325. `b = select(f, a);     [ (setq b (remove-if-not f a)) ]'
  326.      Sets b to a copy of a, omitting values causing function f to
  327.      return false.
  328.  
  329. `c = merge(a, b, f);   [ (setq c (merge a b f)) ]'
  330.      Sets c to a list containing the ordered elements (using the
  331.      comparison function f) of the sorted lists a and b.
  332.  
  333. Destructive operations
  334. ======================
  335.  
  336. `a.append(b);          [ (rplacd (last a) b) ]'
  337.      appends b to the end of a. No new nodes are constructed.
  338.  
  339. `a.prepend(b);         [ (setq a (append b a)) ]'
  340.      prepends b to the beginning of a.
  341.  
  342. `a.del(x);             [ (delete x a) ]'
  343.      deletes all nodes with value x from a.
  344.  
  345. `a.del(f);             [ (delete-if f a) ]'
  346.      deletes all nodes causing function f to return true.
  347.  
  348. `a.select(f);          [ (delete-if-not f a) ]'
  349.      deletes all nodes causing function f to return false.
  350.  
  351. `a.reverse();          [ (nreverse a) ]'
  352.      reverses a in-place.
  353.  
  354. `a.sort(f);            [ (sort a f) ]'
  355.      sorts a in-place using ordering (comparison) function f.
  356.  
  357. `a.apply(f);           [ (mapc f a) ]'
  358.      Applies void function f (int x) to each element of a.
  359.  
  360. `a.subst(int old, int repl); [ (nsubst repl old a) ]'
  361.      substitutes repl for each occurrence of old in a. Note the
  362.      different argument order than the Lisp version.
  363.  
  364. Other operations
  365. ================
  366.  
  367. `a.find(int x);       [ (find x a) ]'
  368.      returns the intList at the first occurrence of x.
  369.  
  370. `a.find(b);           [ (find b a) ]'
  371.      returns the intList at the first occurrence of sublist b.
  372.  
  373. `a.contains(int x);    [ (member x a) ]'
  374.      returns true if a contains x.
  375.  
  376. `a.contains(b);        [ (member b a) ]'
  377.      returns true if a contains sublist b.
  378.  
  379. `a.position(int x);    [ (position x a) ]'
  380.      returns the zero-based index of x in a, or -1 if x does not occur.
  381.  
  382. `int x = a.reduce(f, int base); [ (reduce f a :initial-value base) ]'
  383.      Accumulates the result of applying int function f(int, int) to
  384.      successive elements of a, starting with base.
  385.  
  386. 
  387. File: libg++.info,  Node: LinkList,  Next: Vector,  Prev: List,  Up: Top
  388.  
  389. Linked Lists
  390. ************
  391.  
  392.    SLLists provide pseudo-generic singly linked lists.  DLLists provide
  393. doubly linked lists.  The lists are designed for the simple maintenance
  394. of elements in a linked structure, and do not provide the more extensive
  395. operations (or node-sharing) of class `List'. They behave similarly to
  396. the `slist' and similar classes described by Stroustrup.
  397.  
  398.    All list nodes are created dynamically. Assignment is performed via
  399. copying.
  400.  
  401.    Class `DLList' supports all `SLList' operations, plus additional
  402. operations described below.
  403.  
  404.    For purposes of illustration, assume the specification of class
  405. `intSLList'. In addition to the operations listed here, SLLists support
  406. traversal via Pixes. *Note Pix::
  407.  
  408. `intSLList a;'
  409.      Declares a to be an empty list.
  410.  
  411. `intSLList b = a;'
  412.      Sets b to an element-by-element copy of a.
  413.  
  414. `a.empty()'
  415.      returns true if a contains no elements
  416.  
  417. `a.length();'
  418.      returns the number of elements in a.
  419.  
  420. `a.prepend(x);'
  421.      places x at the front of the list.
  422.  
  423. `a.append(x);'
  424.      places x at the end of the list.
  425.  
  426. `a.join(b)'
  427.      places all nodes from b to the end of a, simultaneously destroying
  428.      b.
  429.  
  430. `x = a.front()'
  431.      returns a reference to the item stored at the head of the list, or
  432.      triggers an error if the list is empty.
  433.  
  434. `a.rear()'
  435.      returns a reference to the rear of the list, or triggers an error
  436.      if the list is empty.
  437.  
  438. `x = a.remove_front()'
  439.      deletes and returns the item stored at the head of the list.
  440.  
  441. `a.del_front()'
  442.      deletes the first element, without returning it.
  443.  
  444. `a.clear()'
  445.      deletes all items from the list.
  446.  
  447. `a.ins_after(Pix i, item);'
  448.      inserts item after position i. If i is null, insertion is at the
  449.      front.
  450.  
  451. `a.del_after(Pix i);'
  452.      deletes the element following i. If i is 0, the first item is
  453.      deleted.
  454.  
  455. Doubly linked lists
  456. ===================
  457.  
  458.    Class `DLList' supports the following additional operations, as well
  459. as backward traversal via Pixes.
  460.  
  461. `x = a.remove_rear();'
  462.      deletes and returns the item stored at the rear of the list.
  463.  
  464. `a.del_rear();'
  465.      deletes the last element, without returning it.
  466.  
  467. `a.ins_before(Pix i, x)'
  468.      inserts x before the i.
  469.  
  470. `a.del(Pix& iint dir = 1)'
  471.      deletes the item at the current position, then advances forward if
  472.      dir is positive, else backward.
  473.  
  474. 
  475. File: libg++.info,  Node: Vector,  Next: Plex,  Prev: LinkList,  Up: Top
  476.  
  477. Vector classes
  478. **************
  479.  
  480.    The files `g++-include/Vec.ccP' and `g++-include/AVec.ccP' provide
  481. pseudo-generic standard array-based vector operations.  The
  482. corresponding header files are `g++-include/Vec.hP' and
  483. `g++-include/AVec.hP'.  Class `Vec' provides operations suitable for
  484. any base class that includes an equality operator. Subclass `AVec'
  485. provides additional arithmetic operations suitable for base classes
  486. that include the full complement of arithmetic operators.
  487.  
  488.    `Vecs' are constructed and assigned by copying. Thus, they should
  489. normally be passed by reference in applications programs.
  490.  
  491.    Several mapping functions are provided that allow programmers to
  492. specify operations on vectors as a whole.
  493.  
  494.    For illustrative purposes assume that classes `intVec' and `intAVec'
  495. have been generated via `genclass'.
  496.  
  497. Constructors and assignment
  498. ===========================
  499.  
  500. `intVec a;'
  501.      declares a to be an empty vector. Its size may be changed via
  502.      resize.
  503.  
  504. `intVec a(10);'
  505.      declares a to be an uninitialized vector of ten elements (numbered
  506.      0-9).
  507.  
  508. `intVec b(6, 0);'
  509.      declares b to be a vector of six elements, all initialized to
  510.      zero. Any value can be used as the initial fill argument.
  511.  
  512. `a = b;'
  513.      Copies b to a. a is resized to be the same as b.
  514.  
  515. `a = b.at(2, 4)'
  516.      constructs a from the 4 elements of b starting at b[2].
  517.  
  518.    Assume declarations of `intVec a, b, c' and `int i, x' in the
  519. following.
  520.  
  521. Status and access
  522. =================
  523.  
  524. `a.capacity();'
  525.      returns the number of elements that can be held in a.
  526.  
  527. `a.resize(20);'
  528.      sets a's length to 20. All elements are unchanged, except that if
  529.      the new size is smaller than the original, than trailing elements
  530.      are deleted, and if greater, trailing elements are uninitialized.
  531.  
  532. `a[i];'
  533.      returns a reference to the i'th element of a, or produces an error
  534.      if i is out of range.
  535.  
  536. `a.elem(i)'
  537.      returns a reference to the i'th element of a. Unlike the `[]'
  538.      operator, i is not checked to ensure that it is within range.
  539.  
  540. `a == b;'
  541.      returns true if a and b contain the same elements in the same
  542.      order.
  543.  
  544. `a != b;'
  545.      is the converse of a == b.
  546.  
  547. Constructive operations
  548. =======================
  549.  
  550. `c = concat(a, b);'
  551.      sets c to the new vector constructed from all of the elements of a
  552.      followed by all of b.
  553.  
  554. `c = map(f, a);'
  555.      sets c to the new vector constructed by applying int function
  556.      f(int) to each element of a.
  557.  
  558. `c = merge(a, b, f);'
  559.      sets c to the new vector constructed by merging the elements of
  560.      ordered vectors a and b using ordering (comparison) function f.
  561.  
  562. `c = combine(f, a, b);'
  563.      sets c to the new vector constructed by applying int function
  564.      f(int, int) to successive pairs of a and b. The result has length
  565.      the shorter of a and b.
  566.  
  567. `c = reverse(a)'
  568.      sets c to a, with elements in reverse order.
  569.  
  570. Destructive operations
  571. ======================
  572.  
  573. `a.reverse();'
  574.      reverses a in-place.
  575.  
  576. `a.sort(f)'
  577.      sorts a in-place using comparison function f. The sorting method
  578.      is a variation of the quicksort functions supplied with GNU emacs.
  579.  
  580. `a.fill(0, 4, 2)'
  581.      fills the 2 elements starting at a[4] with zero.
  582.  
  583. Other operations
  584. ================
  585.  
  586. `a.apply(f)'
  587.      applies function f to each element in a.
  588.  
  589. `x = a.reduce(f, base)'
  590.      accumulates the results of applying function f to successive
  591.      elements of a starting with base.
  592.  
  593. `a.index(int targ);'
  594.      returns the index of the leftmost occurrence of the target, or -1,
  595.      if it does not occur.
  596.  
  597. `a.error(char* msg)'
  598.      invokes the error handler. The default version prints the error
  599.      message, then aborts.
  600.  
  601. AVec operations.
  602. ================
  603.  
  604.    AVecs provide additional arithmetic operations.  All vector-by-vector
  605. operators generate an error if the vectors are not the same length. The
  606. following operations are provided, for `AVecs a, b' and base element
  607. (scalar) `s'.
  608.  
  609. `a = b;'
  610.      Copies b to a. a and b must be the same size.
  611.  
  612. `a = s;'
  613.      fills all elements of a with the value s. a is not resized.
  614.  
  615. `a + s; a - s; a * s; a / s'
  616.      adds, subtracts, multiplies, or divides each element of a with the
  617.      scalar.
  618.  
  619. `a += s; a -= s; a *= s; a /= s;'
  620.      adds, subtracts, multiplies, or divides the scalar into a.
  621.  
  622. `a + b; a - b; product(a, b), quotient(a, b)'
  623.      adds, subtracts, multiplies, or divides corresponding elements of
  624.      a and b.
  625.  
  626. `a += b; a -= b; a.product(b); a.quotient(b);'
  627.      adds, subtracts, multiplies, or divides corresponding elements of
  628.      b into a.
  629.  
  630. `s = a * b;'
  631.      returns the inner (dot) product of a and b.
  632.  
  633. `x = a.sum();'
  634.      returns the sum of elements of a.
  635.  
  636. `x = a.sumsq();'
  637.      returns the sum of squared elements of a.
  638.  
  639. `x = a.min();'
  640.      returns the minimum element of a.
  641.  
  642. `x = a.max();'
  643.      returns the maximum element of a.
  644.  
  645. `i = a.min_index();'
  646.      returns the index of the minimum element of a.
  647.  
  648. `i = a.max_index();'
  649.      returns the index of the maximum element of a.
  650.  
  651.      Note that it is possible to apply vector versions other arithmetic
  652.      operators via the mapping functions. For example, to set vector b
  653.      to the  cosines of doubleVec a, use `b = map(cos, a);'.  This is
  654.      often more efficient than performing the operations in an
  655.      element-by-element fashion.
  656.  
  657. 
  658. File: libg++.info,  Node: Plex,  Next: Stack,  Prev: Vector,  Up: Top
  659.  
  660. Plex classes
  661. ************
  662.  
  663.    A "Plex" is a kind of array with the following properties:
  664.  
  665.    * Plexes may have arbitrary upper and lower index bounds. For example
  666.      a Plex may be declared to run from indices -10 .. 10.
  667.  
  668.    * Plexes may be dynamically expanded at both the lower and upper
  669.      bounds of the array in steps of one element.
  670.  
  671.    * Only elements that have been specifically initialized or added may
  672.      be accessed.
  673.  
  674.    * Elements may be accessed via indices. Indices are always checked
  675.      for validity at run time.  Plexes may be traversed via simple
  676.      variations of standard array indexing loops.
  677.  
  678.    * Plex elements may be accessed and traversed via Pixes.
  679.  
  680.    * Plex-to-Plex assignment and related operations on entire Plexes
  681.      are supported.
  682.  
  683.    * Plex classes contain methods to help programmers check the validity
  684.      of indexing and pointer operations.
  685.  
  686.    * Plexes form "natural" base classes for many restricted-access data
  687.      structures relying on logically contiguous indices, such as
  688.      array-based stacks and queues.
  689.  
  690.    * Plexes are implemented as pseudo-generic classes, and must be
  691.      generated via the `genclass' utility.
  692.  
  693.    Four subclasses of Plexes are supported: A `FPlex' is a Plex that
  694. may only grow or shrink within declared bounds; an `XPlex' may
  695. dynamically grow or shrink without bounds; an `RPlex' is the same as an
  696. `XPlex' but better supports indexing with poor locality of reference; a
  697. `MPlex' may grow or shrink, and additionally allows the logical
  698. deletion and restoration of elements. Because these classes are virtual
  699. subclasses of the "abstract" class `Plex', it is possible to write user
  700. code such as `void f(Plex& a) ...' that operates on any kind of Plex.
  701. However, as with nearly any virtual class, specifying the particular
  702. Plex class being used results in more efficient code.
  703.  
  704.    Plexes are implemented as a linked list of `IChunks'.  Each chunk
  705. contains a part of the array. Chunk sizes may be specified within Plex
  706. constructors.  Default versions also exist, that use a `#define'd'
  707. default.  Plexes grow by filling unused space in existing chunks, if
  708. possible, else, except for FPlexes, by adding another chunk.  Whenever
  709. Plexes grow by a new chunk, the default element constructors (i.e.,
  710. those which take no arguments) for all chunk elements are called at
  711. once. When Plexes shrink, destructors for the elements are not called
  712. until an entire chunk is freed. For this reason, Plexes (like C++
  713. arrays) should only be used for elements with default constructors and
  714. destructors that have no side effects.
  715.  
  716.    Plexes may be indexed and used like arrays, although traversal
  717. syntax is slightly different. Even though Plexes maintain elements in
  718. lists of chunks, they are implemented so that iteration and other
  719. constructs that maintain locality of reference require very little
  720. overhead over that for simple array traversal Pix-based traversal is
  721. also supported. For example, for a plex, p, of ints, the following
  722. traversal methods could be used.
  723.  
  724.      for (int i = p.low(); i < p.fence(); p.next(i)) use(p[i]);
  725.      for (int i = p.high(); i > p.ecnef(); p.prev(i)) use(p[i]);
  726.      for (Pix t = p.first(); t != 0; p.next(t)) use(p(i));
  727.      for (Pix t = p.last(); t != 0; p.prev(t)) use(p(i));
  728.  
  729.    Except for MPlexes, simply using `++i' and `--i' works just as well
  730. as `p.next(i)' and `p.prev(i)' when traversing by index.  Index-based
  731. traversal is generally a bit faster than Pix-based traversal.
  732.  
  733.    `XPlexes' and `MPlexes' are less than optimal for applications in
  734. which widely scattered elements are indexed, as might occur when using
  735. Plexes as hash tables or "manually" allocated linked lists.  In such
  736. applications, `RPlexes' are often preferable. `RPlexes' use a secondary
  737. chunk index table that requires slightly greater, but entirely uniform
  738. overhead per index operation.
  739.  
  740.    Even though they may grow in either direction, Plexes are normally
  741. constructed so that their "natural" growth direction is upwards, in
  742. that default chunk construction leaves free space, if present, at the
  743. end of the plex. However, if the chunksize arguments to constructors
  744. are negative, they leave space at the beginning.
  745.  
  746.    All versions of Plexes support the following basic capabilities.
  747. (letting `Plex' stand for the type name constructed via the genclass
  748. utility (e.g., `intPlex', `doublePlex')).  Assume declarations of `Plex
  749. p, q', `int i, j', base element `x', and Pix `pix'.
  750.  
  751. `Plex p;'
  752.      Declares p to be an initially zero-sized Plex with low index of
  753.      zero, and the default chunk size. For FPlexes, chunk sizes
  754.      represent maximum sizes.
  755.  
  756. `Plex p(int size);'
  757.      Declares p to be an initially zero-sized Plex with low index of
  758.      zero, and the indicated chunk size. If size is negative, then the
  759.      Plex is created with free space at the beginning of the Plex,
  760.      allowing more efficient add_low() operations. Otherwise, it leaves
  761.      space at the end.
  762.  
  763. `Plex p(int low, int size);'
  764.      Declares p to be an initially zero-sized Plex with low index of
  765.      low, and the indicated chunk size.
  766.  
  767. `Plex p(int low, int high, Base initval, int size = 0);'
  768.      Declares p to be a Plex with indices from low to high, initially
  769.      filled with initval, and the indicated chunk size if specified,
  770.      else the default or (high - low + 1), whichever is greater.
  771.  
  772. `Plex q(p);'
  773.      Declares q to be a copy of p.
  774.  
  775. `p = q;'
  776.      Copies Plex q into p, deleting its previous contents.
  777.  
  778. `p.length()'
  779.      Returns the number of elements in the Plex.
  780.  
  781. `p.empty()'
  782.      Returns true if Plex p contains no elements.
  783.  
  784. `p.full()'
  785.      Returns true if Plex p cannot be expanded. This always returns
  786.      false for XPlexes and MPlexes.
  787.  
  788. `p[i]'
  789.      Returns a reference to the i'th element of p. An exception (error)
  790.      occurs if i is not a valid index.
  791.  
  792. `p.valid(i)'
  793.      Returns true if i is a valid index into Plex p.
  794.  
  795. `p.low(); p.high();'
  796.      Return the minimum (maximum) valid index of the Plex, or the high
  797.      (low) fence if the plex is empty.
  798.  
  799. `p.ecnef(); p.fence();'
  800.      Return the index one position past the minimum (maximum) valid
  801.      index.
  802.  
  803. `p.next(i); i = p.prev(i);'
  804.      Set i to the next (previous) index. This index may not be within
  805.      bounds.
  806.  
  807. `p(pix)'
  808.      returns a reference to the item at Pix pix.
  809.  
  810. `pix = p.first(); pix = p.last();'
  811.      Return the minimum (maximum) valid Pix of the Plex, or 0 if the
  812.      plex is empty.
  813.  
  814. `p.next(pix); p.prev(pix);'
  815.      set pix to the next (previous) Pix, or 0 if there is none.
  816.  
  817. `p.owns(pix)'
  818.      Returns true if the Plex contains the element associated with pix.
  819.  
  820. `p.Pix_to_index(pix)'
  821.      If pix is a valid Pix to an element of the Plex, returns its
  822.      corresponding index, else raises an exception.
  823.  
  824. `ptr = p.index_to_Pix(i)'
  825.      if i is a valid index, returns a the corresponding Pix.
  826.  
  827. `p.low_element(); p.high_element();'
  828.      Return a reference to the element at the minimum (maximum) valid
  829.      index.  An exception occurs if the Plex is empty.
  830.  
  831. `p.can_add_low();  p.can_add_high();'
  832.      Returns true if the plex can be extended one element downward
  833.      (upward).  These always return true for XPlex and MPlex.
  834.  
  835. `j = p.add_low(x); j = p.add_high(x);'
  836.      Extend the Plex by one element downward (upward). The new minimum
  837.      (maximum) index is returned.
  838.  
  839. `j = p.del_low(); j = p.del_high()'
  840.      Shrink the Plex by one element on the low (high) end. The new
  841.      minimum (maximum) element is returned. An exception occurs if the
  842.      Plex is empty.
  843.  
  844. `p.append(q);'
  845.      Append all of Plex q to the high side of p.
  846.  
  847. `p.prepend(q);'
  848.      Prepend all of q to the low side of p.
  849.  
  850. `p.clear()'
  851.      Delete all elements, resetting p to a zero-sized Plex.
  852.  
  853. `p.reset_low(i);'
  854.      Resets p to be indexed starting at low() = i. For example.  if p
  855.      were initially declared via `Plex p(0, 10, 0)', and then
  856.      re-indexed via `p.reset_low(5)', it could then be indexed from
  857.      indices 5 .. 14.
  858.  
  859. `p.fill(x)'
  860.      sets all p[i] to x.
  861.  
  862. `p.fill(x, lo, hi)'
  863.      sets all of p[i] from lo to hi, inclusive, to x.
  864.  
  865. `p.reverse()'
  866.      reverses p in-place.
  867.  
  868. `p.chunk_size()'
  869.      returns the chunk size used for the plex.
  870.  
  871. `p.error(const char * msg)'
  872.      calls the resettable error handler.
  873.  
  874.    MPlexes are plexes with bitmaps that allow items to be logically
  875. deleted and restored. They behave like other plexes, but also support
  876. the following additional and modified capabilities:
  877.  
  878. `p.del_index(i); p.del_Pix(pix)'
  879.      logically deletes p[i] (p(pix)). After deletion, attempts to
  880.      access p[i] generate a error. Indexing via low(), high(), prev(),
  881.      and next() skip the element. Deleting an element never changes the
  882.      logical bounds of the plex.
  883.  
  884. `p.undel_index(i); p.undel_Pix(pix)'
  885.      logically undeletes p[i] (p(pix)).
  886.  
  887. `p.del_low(); p.del_high()'
  888.      Delete the lowest (highest) undeleted element, resetting the
  889.      logical bounds of the plex to the next lowest (highest) undeleted
  890.      index. Thus, MPlex del_low() and del_high() may shrink the bounds
  891.      of the plex by more than one index.
  892.  
  893. `p.adjust_bounds()'
  894.      Resets the low and high bounds of the Plex to the indexes of the
  895.      lowest and highest actual undeleted elements.
  896.  
  897. `int i = p.add(x)'
  898.      Adds x in an unused index, if possible, else performs add_high.
  899.  
  900. `p.count()'
  901.      returns the number of valid (undeleted) elements.
  902.  
  903. `p.available()'
  904.      returns the number of available (deleted) indices.
  905.  
  906. `int i = p.unused_index()'
  907.      returns the index of some deleted element, if one exists, else
  908.      triggers an error. An unused element may be reused via undel.
  909.  
  910. `pix = p.unused_Pix()'
  911.      returns the pix of some deleted element, if one exists, else 0.
  912.      An unused element may be reused via undel.
  913.  
  914. 
  915. File: libg++.info,  Node: Stack,  Next: Queue,  Prev: Plex,  Up: Top
  916.  
  917. Stacks
  918. ******
  919.  
  920.    Stacks are declared as an "abstract" class. They are currently
  921. implemented in any of three ways.
  922.  
  923. `VStack'
  924.      implement fixed sized stacks via arrays.
  925.  
  926. `XPStack'
  927.      implement dynamically-sized stacks via XPlexes.
  928.  
  929. `SLStack'
  930.      implement dynamically-size stacks via linked lists.
  931.  
  932.    All possess the same capabilities. They differ only in constructors.
  933. VStack constructors require a fixed maximum capacity argument.  XPStack
  934. constructors optionally take a chunk size argument.  SLStack
  935. constructors take no argument.
  936.  
  937.    Assume the declaration of a base element `x'.
  938.  
  939. `Stack s;  or Stack s(int capacity)'
  940.      declares a Stack.
  941.  
  942. `s.empty()'
  943.      returns true if stack s is empty.
  944.  
  945. `s.full()'
  946.      returns true if stack s is full. XPStacks and SLStacks never
  947.      become full.
  948.  
  949. `s.length()'
  950.      returns the current number of elements in the stack.
  951.  
  952. `s.push(x)'
  953.      pushes x on stack s.
  954.  
  955. `x = s.pop()'
  956.      pops and returns the top of stack
  957.  
  958. `s.top()'
  959.      returns a reference to the top of stack.
  960.  
  961. `s.del_top()'
  962.      pops, but does not return the top of stack. When large items are
  963.      held on the stack it is often a good idea to use `top()' to
  964.      inspect and use the top of stack, followed by a `del_top()'
  965.  
  966. `s.clear()'
  967.      removes all elements from the stack.
  968.  
  969. 
  970. File: libg++.info,  Node: Queue,  Next: Deque,  Prev: Stack,  Up: Top
  971.  
  972. Queues
  973. ******
  974.  
  975.    Queues are declared as an "abstract" class. They are currently
  976. implemented in any of three ways.
  977.  
  978. `VQueue'
  979.      implement fixed sized Queues via arrays.
  980.  
  981. `XPQueue'
  982.      implement dynamically-sized Queues via XPlexes.
  983.  
  984. `SLQueue'
  985.      implement dynamically-size Queues via linked lists.
  986.  
  987.    All possess the same capabilities; they differ only in constructors.
  988. `VQueue' constructors require a fixed maximum capacity argument.
  989. `XPQueue' constructors optionally take a chunk size argument.
  990. `SLQueue' constructors take no argument.
  991.  
  992.    Assume the declaration of a base element `x'.
  993.  
  994. `Queue q; or Queue q(int capacity);'
  995.      declares a queue.
  996.  
  997. `q.empty()'
  998.      returns true if queue q is empty.
  999.  
  1000. `q.full()'
  1001.      returns true if queue q is full. XPQueues and SLQueues are never
  1002.      full.
  1003.  
  1004. `q.length()'
  1005.      returns the current number of elements in the queue.
  1006.  
  1007. `q.enq(x)'
  1008.      enqueues x on queue q.
  1009.  
  1010. `x = q.deq()'
  1011.      dequeues and returns the front of queue
  1012.  
  1013. `q.front()'
  1014.      returns a reference to the front of queue.
  1015.  
  1016. `q.del_front()'
  1017.      dequeues, but does not return the front of queue
  1018.  
  1019. `q.clear()'
  1020.      removes all elements from the queue.
  1021.  
  1022. 
  1023. File: libg++.info,  Node: Deque,  Next: PQ,  Prev: Queue,  Up: Top
  1024.  
  1025. Double ended Queues
  1026. *******************
  1027.  
  1028.    Deques are declared as an "abstract" class. They are currently
  1029. implemented in two ways.
  1030.  
  1031. `XPDeque'
  1032.      implement dynamically-sized Deques via XPlexes.
  1033.  
  1034. `DLDeque'
  1035.      implement dynamically-size Deques via linked lists.
  1036.  
  1037.    All possess the same capabilities. They differ only in constructors.
  1038. XPDeque constructors optionally take a chunk size argument.  DLDeque
  1039. constructors take no argument.
  1040.  
  1041.    Double-ended queues support both stack-like and queue-like
  1042. capabilities:
  1043.  
  1044.    Assume the declaration of a base element `x'.
  1045.  
  1046. `Deque d; or Deque d(int initial_capacity)'
  1047.      declares a deque.
  1048.  
  1049. `d.empty()'
  1050.      returns true if deque d is empty.
  1051.  
  1052. `d.full()'
  1053.      returns true if deque d is full.  Always returns false in current
  1054.      implementations.
  1055.  
  1056. `d.length()'
  1057.      returns the current number of elements in the deque.
  1058.  
  1059. `d.enq(x)'
  1060.      inserts x at the rear of deque d.
  1061.  
  1062. `d.push(x)'
  1063.      inserts x at the front of deque d.
  1064.  
  1065. `x = d.deq()'
  1066.      dequeues and returns the front of deque
  1067.  
  1068. `d.front()'
  1069.      returns a reference to the front of deque.
  1070.  
  1071. `d.rear()'
  1072.      returns a reference to the rear of the deque.
  1073.  
  1074. `d.del_front()'
  1075.      deletes, but does not return the front of deque
  1076.  
  1077. `d.del_rear()'
  1078.      deletes, but does not return the rear of the deque.
  1079.  
  1080. `d.clear()'
  1081.      removes all elements from the deque.
  1082.  
  1083. 
  1084. File: libg++.info,  Node: PQ,  Next: Set,  Prev: Deque,  Up: Top
  1085.  
  1086. Priority Queue class prototypes.
  1087. ********************************
  1088.  
  1089.    Priority queues maintain collections of objects arranged for fast
  1090. access to the least element.
  1091.  
  1092.    Several prototype implementations of priority queues are supported.
  1093.  
  1094. `XPPQs'
  1095.      implement 2-ary heaps via XPlexes.
  1096.  
  1097. `SplayPQs'
  1098.      implement  PQs via Sleator and Tarjan's (JACM 1985) splay trees.
  1099.      The algorithms use a version of "simple top-down splaying"
  1100.      (described on page 669 of the article).  The simple-splay
  1101.      mechanism for priority queue functions is loosely based on the one
  1102.      used by D. Jones in the C splay tree functions available from
  1103.      volume 14 of the uunet.uu.net archives.
  1104.  
  1105. `PHPQs'
  1106.      implement pairing heaps (as described by Fredman and Sedgewick in
  1107.      `Algorithmica', Vol 1, p111-129).  Storage for heap elements is
  1108.      managed via an internal freelist technique. The constructor allows
  1109.      an initial capacity estimate for freelist space.  The storage is
  1110.      automatically expanded if necessary to hold new items. The
  1111.      deletion technique is a fast "lazy deletion" strategy that marks
  1112.      items as deleted, without reclaiming space until the items come to
  1113.      the top of the heap.
  1114.  
  1115.    All PQ classes support the following operations, for some PQ class
  1116. `Heap', instance `h', `Pix ind', and base class variable `x'.
  1117.  
  1118. `h.empty()'
  1119.      returns true if there are no elements in the PQ.
  1120.  
  1121. `h.length()'
  1122.      returns the number of elements in h.
  1123.  
  1124. `ind = h.enq(x)'
  1125.      Places x in the PQ, and returns its index.
  1126.  
  1127. `x = h.deq()'
  1128.      Dequeues the minimum element of the PQ into x, or generates an
  1129.      error if the PQ is empty.
  1130.  
  1131. `h.front()'
  1132.      returns a reference to the minimum element.
  1133.  
  1134. `h.del_front()'
  1135.      deletes the minimum element.
  1136.  
  1137. `h.clear();'
  1138.      deletes all elements from h;
  1139.  
  1140. `h.contains(x)'
  1141.      returns true if x is in h.
  1142.  
  1143. `h(ind)'
  1144.      returns a reference to the item indexed by ind.
  1145.  
  1146. `ind = h.first()'
  1147.      returns the Pix of first item in the PQ or 0 if empty.  This need
  1148.      not be the Pix of the least element.
  1149.  
  1150. `h.next(ind)'
  1151.      advances ind to the Pix of next element, or 0 if there are no more.
  1152.  
  1153. `ind = h.seek(x)'
  1154.      Sets ind to the Pix of x, or 0 if x is not in h.
  1155.  
  1156. `h.del(ind)'
  1157.      deletes the item with Pix ind.
  1158.  
  1159. 
  1160. File: libg++.info,  Node: Set,  Next: Bag,  Prev: PQ,  Up: Top
  1161.  
  1162. Set class prototypes
  1163. ********************
  1164.  
  1165.    Set classes maintain unbounded collections of items containing no
  1166. duplicate elements.
  1167.  
  1168.    These are currently implemented in several ways, differing in
  1169. representation strategy, algorithmic efficiency, and appropriateness for
  1170. various tasks. (Listed next to each are average (followed by worst-case,
  1171. if different) time complexities for [a] adding, [f] finding (via seek,
  1172. contains), [d] deleting, elements, and [c] comparing (via ==, <=) and
  1173. [m] merging (via |=, -=, &=) sets).
  1174.  
  1175. `XPSets'
  1176.      implement unordered sets via XPlexes.  ([a O(n)], [f O(n)], [d
  1177.      O(n)], [c O(n^2)] [m O(n^2)]).
  1178.  
  1179. `OXPSets'
  1180.      implement ordered sets via XPlexes.  ([a O(n)], [f O(log n)], [d
  1181.      O(n)], [c O(n)] [m O(n)]).
  1182.  
  1183. `SLSets'
  1184.      implement unordered sets via linked lists ([a O(n)], [f O(n)], [d
  1185.      O(n)], [c O(n^2)] [m O(n^2)]).
  1186.  
  1187. `OSLSets'
  1188.      implement ordered sets via linked lists ([a O(n)], [f O(n)], [d
  1189.      O(n)], [c O(n)] [m O(n)]).
  1190.  
  1191. `AVLSets'
  1192.      implement ordered sets via threaded AVL trees ([a O(log n)], [f
  1193.      O(log n)], [d O(log n)], [c O(n)] [m O(n)]).
  1194.  
  1195. `BSTSets'
  1196.      implement ordered sets via binary search trees. The trees may be
  1197.      manually rebalanced via the O(n) `balance()' member function.  ([a
  1198.      O(log n)/O(n)], [f O(log n)/O(n)], [d O(log n)/O(n)], [c O(n)] [m
  1199.      O(n)]).
  1200.  
  1201. `SplaySets'
  1202.      implement ordered sets via Sleator and Tarjan's (JACM 1985) splay
  1203.      trees. The algorithms use a version of "simple top-down splaying"
  1204.      (described on page 669 of the article).  (Amortized: [a O(log n)],
  1205.      [f O(log n)], [d O(log n)], [c O(n)] [m O(n log n)]).
  1206.  
  1207. `VHSets'
  1208.      implement unordered sets via hash tables.  The tables are
  1209.      automatically resized when their capacity is exhausted.  ([a
  1210.      O(1)/O(n)], [f O(1)/O(n)], [d O(1)/O(n)], [c O(n)/O(n^2)] [m
  1211.      O(n)/O(n^2)]).
  1212.  
  1213. `VOHSets'
  1214.      implement unordered sets via ordered hash tables The tables are
  1215.      automatically resized when their capacity is exhausted.  ([a
  1216.      O(1)/O(n)], [f O(1)/O(n)], [d O(1)/O(n)], [c O(n)/O(n^2)] [m
  1217.      O(n)/O(n^2)]).
  1218.  
  1219. `CHSets'
  1220.      implement unordered sets via chained hash tables.  ([a O(1)/O(n)],
  1221.      [f O(1)/O(n)], [d O(1)/O(n)], [c O(n)/O(n^2)] [m O(n)/O(n^2)]).
  1222.  
  1223.    The different implementations differ in whether their constructors
  1224. require an argument specifying their initial capacity. Initial
  1225. capacities are required for plex and hash table based Sets.  If none is
  1226. given `DEFAULT_INITIAL_CAPACITY' (from `<T>defs.h') is used.
  1227.  
  1228.    Sets support the following operations, for some class `Set',
  1229. instances `a' and `b', `Pix ind', and base element `x'. Since all
  1230. implementations are virtual derived classes of the `<T>Set' class, it
  1231. is possible to mix and match operations across different
  1232. implementations, although, as usual, operations are generally faster
  1233. when the particular classes are specified in functions operating on
  1234. Sets.
  1235.  
  1236.    Pix-based operations are more fully described in the section on
  1237. Pixes. *Note Pix::
  1238.  
  1239. `Set a; or Set a(int initial_size);'
  1240.      Declares a to be an empty Set. The second version is allowed in
  1241.      set classes that require initial capacity or sizing specifications.
  1242.  
  1243. `a.empty()'
  1244.      returns true if a is empty.
  1245.  
  1246. `a.length()'
  1247.      returns the number of elements in a.
  1248.  
  1249. `Pix ind = a.add(x)'
  1250.      inserts x into a, returning its index.
  1251.  
  1252. `a.del(x)'
  1253.      deletes x from a.
  1254.  
  1255. `a.clear()'
  1256.      deletes all elements from a;
  1257.  
  1258. `a.contains(x)'
  1259.      returns true if x is in a.
  1260.  
  1261. `a(ind)'
  1262.      returns a reference to the item indexed by ind.
  1263.  
  1264. `ind = a.first()'
  1265.      returns the Pix of first item in the set or 0 if the Set is empty.
  1266.      For ordered Sets, this is the Pix of the least element.
  1267.  
  1268. `a.next(ind)'
  1269.      advances ind to the Pix of next element, or 0 if there are no more.
  1270.  
  1271. `ind = a.seek(x)'
  1272.      Sets ind to the Pix of x, or 0 if x is not in a.
  1273.  
  1274. `a == b'
  1275.      returns true if a and b contain all the same elements.
  1276.  
  1277. `a != b'
  1278.      returns true if a and b do not contain all the same elements.
  1279.  
  1280. `a <= b'
  1281.      returns true if a is a subset of b.
  1282.  
  1283. `a |= b'
  1284.      Adds all elements of b to a.
  1285.  
  1286. `a -= b'
  1287.      Deletes all elements of b from a.
  1288.  
  1289. `a &= b'
  1290.      Deletes all elements of a not occurring in b.
  1291.  
  1292. 
  1293. File: libg++.info,  Node: Bag,  Next: Map,  Prev: Set,  Up: Top
  1294.  
  1295. Bag class prototypes
  1296. ********************
  1297.  
  1298.    Bag classes maintain unbounded collections of items potentially
  1299. containing  duplicate elements.
  1300.  
  1301.    These are currently implemented in several ways, differing in
  1302. representation strategy, algorithmic efficiency, and appropriateness for
  1303. various tasks. (Listed next to each are average (followed by worst-case,
  1304. if different) time complexities for [a] adding, [f] finding (via seek,
  1305. contains), [d] deleting elements).
  1306.  
  1307. `XPBags'
  1308.      implement unordered Bags via XPlexes.  ([a O(1)], [f O(n)], [d
  1309.      O(n)]).
  1310.  
  1311. `OXPBags'
  1312.      implement ordered Bags via XPlexes.  ([a O(n)], [f O(log n)], [d
  1313.      O(n)]).
  1314.  
  1315. `SLBags'
  1316.      implement unordered Bags via linked lists ([a O(1)], [f O(n)], [d
  1317.      O(n)]).
  1318.  
  1319. `OSLBags'
  1320.      implement ordered Bags via linked lists ([a O(n)], [f O(n)], [d
  1321.      O(n)]).
  1322.  
  1323. `SplayBags'
  1324.      implement ordered Bags via Sleator and Tarjan's (JACM 1985) splay
  1325.      trees. The algorithms use a version of "simple top-down splaying"
  1326.      (described on page 669 of the article).  (Amortized: [a O(log n)],
  1327.      [f O(log n)], [d O(log n)]).
  1328.  
  1329. `VHBags'
  1330.      implement unordered Bags via hash tables.  The tables are
  1331.      automatically resized when their capacity is exhausted.  ([a
  1332.      O(1)/O(n)], [f O(1)/O(n)], [d O(1)/O(n)]).
  1333.  
  1334. `CHBags'
  1335.      implement unordered Bags via chained hash tables.  ([a O(1)/O(n)],
  1336.      [f O(1)/O(n)], [d O(1)/O(n)]).
  1337.  
  1338.    The implementations differ in whether their constructors require an
  1339. argument to specify their initial capacity. Initial capacities are
  1340. required for plex and hash table based Bags.  If none is given
  1341. `DEFAULT_INITIAL_CAPACITY' (from `<T>defs.h') is used.
  1342.  
  1343.    Bags support the following operations, for some class `Bag',
  1344. instances `a' and `b', `Pix ind', and base element `x'. Since all
  1345. implementations are virtual derived classes of the `<T>Bag' class, it
  1346. is possible to mix and match operations across different
  1347. implementations, although, as usual, operations are generally faster
  1348. when the particular classes are specified in functions operating on
  1349. Bags.
  1350.  
  1351.    Pix-based operations are more fully described in the section on
  1352. Pixes. *Note Pix::
  1353.  
  1354. `Bag a; or Bag a(int initial_size)'
  1355.      Declares a to be an empty Bag. The second version is allowed in
  1356.      Bag classes that require initial capacity or sizing specifications.
  1357.  
  1358. `a.empty()'
  1359.      returns true if a is empty.
  1360.  
  1361. `a.length()'
  1362.      returns the number of elements in a.
  1363.  
  1364. `ind = a.add(x)'
  1365.      inserts x into a, returning its index.
  1366.  
  1367. `a.del(x)'
  1368.      deletes one occurrence of x from a.
  1369.  
  1370. `a.remove(x)'
  1371.      deletes all occurrences of x from a.
  1372.  
  1373. `a.clear()'
  1374.      deletes all elements from a;
  1375.  
  1376. `a.contains(x)'
  1377.      returns true if x is in a.
  1378.  
  1379. `a.nof(x)'
  1380.      returns the number of occurrences of x in a.
  1381.  
  1382. `a(ind)'
  1383.      returns a reference to the item indexed by ind.
  1384.  
  1385. `int = a.first()'
  1386.      returns the Pix of first item in the Bag or 0 if the Bag is empty.
  1387.      For ordered Bags, this is the Pix of the least element.
  1388.  
  1389. `a.next(ind)'
  1390.      advances ind to the Pix of next element, or 0 if there are no more.
  1391.  
  1392. `ind = a.seek(x. Pix from = 0)'
  1393.      Sets ind to the Pix of the next occurrence x, or 0 if there are
  1394.      none.  If from is 0, the first occurrence is returned, else the
  1395.      following from.
  1396.  
  1397. 
  1398. File: libg++.info,  Node: Map,  Next: GetOpt,  Prev: Bag,  Up: Top
  1399.  
  1400. Map Class Prototypes
  1401. ********************
  1402.  
  1403.    Maps support associative array operations (insertion, deletion, and
  1404. membership of records based on an associated key). They require the
  1405. specification of two types, the key type and the contents type.
  1406.  
  1407.    These are currently implemented in several ways, differing in
  1408. representation strategy, algorithmic efficiency, and appropriateness for
  1409. various tasks. (Listed next to each are average (followed by worst-case,
  1410. if different) time complexities for [a] accessing (via op [],
  1411. contains), [d] deleting elements).
  1412.  
  1413. `AVLMaps'
  1414.      implement ordered Maps via threaded AVL trees ([a O(log n)], [d
  1415.      O(log n)]).
  1416.  
  1417. `RAVLMaps'
  1418.      Similar, but also maintain ranking information, used via
  1419.      `ranktoPix(int r)', that returns the `Pix' of the item at rank r,
  1420.      and `rank(key)' that returns the rank of the corresponding item.
  1421.      ([a O(log n)], [d O(log n)]).
  1422.  
  1423. `SplayMaps'
  1424.      implement ordered Maps via Sleator and Tarjan's (JACM 1985) splay
  1425.      trees. The algorithms use a version of "simple top-down splaying"
  1426.      (described on page 669 of the article).  (Amortized: [a O(log n)],
  1427.      [d O(log n)]).
  1428.  
  1429. `VHMaps'
  1430.      implement unordered Maps via hash tables.  The tables are
  1431.      automatically resized when their capacity is exhausted.  ([a
  1432.      O(1)/O(n)], [d O(1)/O(n)]).
  1433.  
  1434. `CHMaps'
  1435.      implement unordered Maps via chained hash tables.  ([a O(1)/O(n)],
  1436.      [d O(1)/O(n)]).
  1437.  
  1438.    The different implementations differ in whether their constructors
  1439. require an argument specifying their initial capacity. Initial
  1440. capacities are required for hash table based Maps.  If none is given
  1441. `DEFAULT_INITIAL_CAPACITY' (from `<T>defs.h') is used.
  1442.  
  1443.    All Map classes share the following operations (for some Map class,
  1444. `Map' instance `d', `Pix ind' and key variable `k', and contents
  1445. variable `x').
  1446.  
  1447.    Pix-based operations are more fully described in the section on
  1448. Pixes. *Note Pix::
  1449.  
  1450. `Map d(x);  Map d(x, int initial_capacity)'
  1451.      Declare d to be an empty Map. The required argument, x, specifies
  1452.      the default contents, i.e., the contents of an otherwise
  1453.      uninitialized location. The second version, specifying initial
  1454.      capacity is allowed for Maps with an initial capacity argument.
  1455.  
  1456. `d.empty()'
  1457.      returns true if d contains no items.
  1458.  
  1459. `d.length()'
  1460.      returns the number of items in d.
  1461.  
  1462. `d[k]'
  1463.      returns a reference to the contents of item with key k. If no such
  1464.      item exists, it is installed with the default contents.  Thus d[k]
  1465.      = x installs x, and x = d[k] retrieves it.
  1466.  
  1467. `d.contains(k)'
  1468.      returns true if an item with key field k exists in d.
  1469.  
  1470. `d.del(k)'
  1471.      deletes the item with key k.
  1472.  
  1473. `d.clear()'
  1474.      deletes all items from the table.
  1475.  
  1476. `x = d.dflt()'
  1477.      returns the default contents.
  1478.  
  1479. `k = d.key(ind)'
  1480.      returns a reference to the key at Pix ind.
  1481.  
  1482. `x = d.contents(ind)'
  1483.      returns a reference to the contents at Pix ind.
  1484.  
  1485. `ind = d.first()'
  1486.      returns the Pix of the first element in d, or 0 if d is empty.
  1487.  
  1488. `d.next(ind)'
  1489.      advances ind to the next element, or 0 if there are no more.
  1490.  
  1491. `ind = d.seek(k)'
  1492.      returns the Pix of element with key k, or 0 if k is not in d.
  1493.  
  1494. 
  1495. File: libg++.info,  Node: GetOpt,  Next: Projects,  Prev: Map,  Up: Top
  1496.  
  1497. C++ version of the GNU getopt function
  1498. **************************************
  1499.  
  1500.    The GetOpt class provides an efficient and structured mechanism for
  1501. processing command-line options from an application program.  The sample
  1502. program fragment below illustrates a typical use of the GetOpt class
  1503. for some hypothetical application program:
  1504.  
  1505.      #include <stdio.h>
  1506.      #include <GetOpt.h>
  1507.      //...
  1508.      int debug_flag, compile_flag, size_in_bytes;
  1509.      
  1510.      int
  1511.      main (int argc, char **argv)
  1512.      {
  1513.        // Invokes ctor `GetOpt (int argc, char **argv,
  1514.        //                       char *optstring);'
  1515.        GetOpt getopt (argc, argv, "dcs:");
  1516.        int option_char;
  1517.      
  1518.        // Invokes member function `int operator ()(void);'
  1519.        while ((option_char = getopt ()) != EOF)
  1520.          switch (option_char)
  1521.            {
  1522.               case 'd': debug_flag = 1; break;
  1523.               case 'c': compile_flag = 1; break;
  1524.               case 's': size_in_bytes = atoi (getopt.optarg); break;
  1525.               case '?': fprintf (stderr,
  1526.                                  "usage: %s [dcs<size>]\n", argv[0]);
  1527.            }
  1528.      }
  1529.  
  1530.    Unlike the C library version, the libg++ GetOpt class uses its
  1531. constructor to initialize class data members containing the argument
  1532. count, argument vector, and the option string.  This simplifies the
  1533. interface for each subsequent call to member function `int operator
  1534. ()(void)'.
  1535.  
  1536.    The C version, on the other hand, uses hidden static variables to
  1537. retain the option string and argument list values between calls to
  1538. `getopt'.  This complicates the `getopt' interface since the argument
  1539. count, argument vector, and option string must be passed as parameters
  1540. for each invocation.  For the C version, the loop in the previous
  1541. example becomes:
  1542.  
  1543.        while ((option_char = getopt (argc, argv, "dcs:")) != EOF)
  1544.          // ...
  1545.  
  1546.    which requires extra overhead to pass the parameters for every call.
  1547.  
  1548.    Along with the GetOpt constructor and `int operator ()(void)', the
  1549. other relevant elements of class GetOpt are:
  1550.  
  1551. `char *optarg'
  1552.      Used for communication from `operator ()(void)' to the caller.
  1553.      When `operator ()(void)' finds an option that takes an argument,
  1554.      the argument value is stored here.
  1555.  
  1556. `int optind'
  1557.      Index in `argv' of the next element to be scanned.  This is used
  1558.      for communication to and from the caller and for communication
  1559.      between successive calls to `operator ()(void)'.
  1560.  
  1561.      When `operator ()(void)' returns EOF, this is the index of the
  1562.      first of the non-option elements that the caller should itself
  1563.      scan.
  1564.  
  1565.      Otherwise, `optind' communicates from one call to the next how much
  1566.      of `argv' has been scanned so far.
  1567.  
  1568.    The libg++ version of GetOpt acts like standard UNIX `getopt' for
  1569. the calling routine, but it behaves differently for the user, since it
  1570. allows the user to intersperse the options with the other arguments.
  1571.  
  1572.    As GetOpt works, it permutes the elements of `argv' so that, when it
  1573. is done, all the options precede everything else.  Thus all application
  1574. programs are extended to handle flexible argument order.
  1575.  
  1576.    Setting the environment variable _POSIX_OPTION_ORDER disables
  1577. permutation.  Then the behavior is completely standard.
  1578.  
  1579.