<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta name="generator" content="HTML Tidy for Linux/x86 (vers 12 April 2005), see www.w3.org" /><title>Introduction</title><meta http-equiv="Content-Type" content="text/html; charset=us-ascii" /></head><body><div id="page"><h1>Introduction</h1><p>This section describes what problems the library attempts tosolve. <a href="motivation.html">Motivation</a> describes thereasons we think it solves these problems better than similarlibraries.</p><h2><a name="assoc" id="assoc">Associative Containers</a></h2><ol><li>Associative containers depend on their policies to a verylarge extent. Implicitly hard-wiring policies can hamper theirperformance and limit their functionality. An efficienthash-based container, for example, requires policies fortesting key equivalence, hashing keys, translating hashvalues into positions within the hash table, and determiningwhen and how to resize the table internally. A tree-basedcontainer can efficiently support order statistics,<i>i.e.</i>, the ability to query what is the order of eachkey within the sequence of keys in the container, but only ifthe container is supplied with a policy to internally updatemeta-data. There are many other such examples.<p></p></li><li>Ideally, all associative containers would share the sameinterface. Unfortunately, underlying data structures andmapping semantics differentiate between different containers.For example, suppose one writes a generic functionmanipulating an associative container <tt>Cntnr</tt>:<pre>template<typename Cntnr>voidsome_op_sequence(Cntnr& r_cnt){...}</pre>then what can one assume about <tt>Cntnr</tt>? The answervaries according to its underlying data structure. If theunderlying data structure of <tt>Cntnr</tt> is based on a tree ortrie, then the order of elements is well defined; otherwise, it isnot, in general. If the underlying data structure of <tt>Cntnr</tt>is based on a collision-chaining hash table, then modifyingr_<tt>Cntnr</tt> will not invalidate its iterators' order; if theunderlying data structure is a probing hash table, then this is notthe case. If the underlying data structure is based on a tree ortrie, then <tt>r_cnt</tt> can efficiently be split; otherwise, itcannot, in general. If the underlying data structure is a red-blacktree, then splitting <tt>r_cnt</tt> is exception-free; if it is anordered-vector tree, exceptions can be thrown.<p></p></li></ol><h2><a name="pq" id="pq">Priority Queues</a></h2><p>Priority queues are useful when one needs to efficientlyaccess a minimum (or maximum) value as the set of valueschanges.</p><ol><li>Most useful data structures for priority queues have arelatively simple structure, as they are geared towardrelatively simple requirements. Unfortunately, these structuresdo not support access to an arbitrary value, which turns out tobe necessary in many algorithms. Say, decreasing an arbitraryvalue in a graph algorithm. Therefore, some extra mechanism isnecessary and must be invented for accessing arbitraryvalues. There are at least two alternatives: embedding anassociative container in a priority queue, or allowingcross-referencing through iterators. The first solution addssignificant overhead; the second solution requires a precisedefinition of iterator invalidation. Which is the nextpoint...<p></p></li><li>Priority queues, like hash-based containers, store values inan order that is meaningless and undefined externally. Forexample, a <tt>push</tt> operation can internally reorganize thevalues. Because of this characteristic, describing a priorityqueues' iterator is difficult: on one hand, the values to whichiterators point can remain valid, but on the other, the logicalorder of iterators can change unpredictably.<p></p></li><li>Roughly speaking, any element that is both inserted to apriority queue (<i>e.g.</i>, through <tt>push</tt>) and removedfrom it (<i>e.g.</i>, through <tt>pop</tt>), incurs alogarithmic overhead (in the amortized sense). Differentunderlying data structures place the actual cost differently:some are optimized for amortized complexity, whereas othersguarantee that specific operations only have a constantcost. One underlying data structure might be chosen if modifyinga value is frequent (Dijkstra's shortest-path algorithm),whereas a different one might be chosenotherwise. Unfortunately, an array-based binary heap - anunderlying data structure that optimizes (in the amortizedsense) <tt>push</tt> and <tt>pop</tt> operations, differs fromthe others in terms of its invalidation guarantees. Other designdecisions also impact the cost and placement of the overhead, atthe expense of more difference in the the kinds of operationsthat the underlying data structure can support. Thesedifferences pose a challenge when creating a uniform interfacefor priority queues.<p></p></li></ol></div></body></html>