Grafalgo
Library of useful data structures and algorithms
|
The Adt class is a base class from which other data structures in grafalgo are derived. More...
#include <Adt.h>
Public Member Functions | |
Adt (index size=26) | |
index | n () const |
Adt (const Adt &) | |
Adt & | operator= (const Adt &) |
Adt & | operator= (Adt &&) |
virtual void | clear ()=0 |
virtual void | resize (int size)=0 |
virtual void | expand (int size)=0 |
virtual string & | item2string (index, string &) const |
virtual string & | toString (string &) const =0 |
Static Public Member Functions | |
static bool | readItem (istream &, index &) |
Read an item from the input stream. | |
Static Public Attributes | |
static const int32_t | MAXINDEX = 0x7ffffff |
static const int32_t | MAXPOSITION = 0x7ffffff |
Protected Attributes | |
index | nn |
defines range of index values for stored items | |
Friends | |
ostream & | operator<< (ostream &out, Adt &a) |
The Adt class is a base class from which other data structures in grafalgo are derived.
The data structures in grafalgo are built using integer index values to refer to specific items (set elements, nodes in search trees, vertices in graphs). In this context, an index is a positive integer in a bounded range 1..N, for some value of N.
The use of index values has a couple advantages over pointers. First, index values can serve as common "names" for items in multiple data structures, eliminating the need to have explicit mappings to relate such items. As one example, when graph vertices are identified by indexes, we can maintain a separate array of application-specific vertex attributes, allowing us to conveniently associate such information without having to embed it in the graph (as we might using templates).
Index values also make it trivial to have fast membership tests for index lists and similar data structures.
bool grafalgo::Adt::readItem | ( | istream & | in, |
index & | x | ||
) | [static] |
Read an item from the input stream.
An item might be an element of a set of vertex in a graph. By convention, data structures that can hold at most 26 items have a string representation that substitutes lower-case letters for the index values used internally (so 1 becomes 'a', 2 becomes 'b' and so forth). On input, if the next non-space character is a lower-case letter, we replace 'a' with 1, etc. If the next non-space character is a digit, we read an integer and interpret it as an index.
in | is an open inpust stream |
x | is a reference to an index in which the input value is returned |
Definition at line 27 of file Adt.cpp.