LLVM API Documentation

ilist.h
Go to the documentation of this file.
00001 //==-- llvm/ADT/ilist.h - Intrusive Linked List Template ---------*- C++ -*-==//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines classes to implement an intrusive doubly linked list class
00011 // (i.e. each node of the list must contain a next and previous field for the
00012 // list.
00013 //
00014 // The ilist_traits trait class is used to gain access to the next and previous
00015 // fields of the node type that the list is instantiated with.  If it is not
00016 // specialized, the list defaults to using the getPrev(), getNext() method calls
00017 // to get the next and previous pointers.
00018 //
00019 // The ilist class itself, should be a plug in replacement for list, assuming
00020 // that the nodes contain next/prev pointers.  This list replacement does not
00021 // provide a constant time size() method, so be careful to use empty() when you
00022 // really want to know if it's empty.
00023 //
00024 // The ilist class is implemented by allocating a 'tail' node when the list is
00025 // created (using ilist_traits<>::createSentinel()).  This tail node is
00026 // absolutely required because the user must be able to compute end()-1. Because
00027 // of this, users of the direct next/prev links will see an extra link on the
00028 // end of the list, which should be ignored.
00029 //
00030 // Requirements for a user of this list:
00031 //
00032 //   1. The user must provide {g|s}et{Next|Prev} methods, or specialize
00033 //      ilist_traits to provide an alternate way of getting and setting next and
00034 //      prev links.
00035 //
00036 //===----------------------------------------------------------------------===//
00037 
00038 #ifndef LLVM_ADT_ILIST_H
00039 #define LLVM_ADT_ILIST_H
00040 
00041 #include "llvm/Support/Compiler.h"
00042 #include <algorithm>
00043 #include <cassert>
00044 #include <cstddef>
00045 #include <iterator>
00046 
00047 namespace llvm {
00048 
00049 template<typename NodeTy, typename Traits> class iplist;
00050 template<typename NodeTy> class ilist_iterator;
00051 
00052 /// ilist_nextprev_traits - A fragment for template traits for intrusive list
00053 /// that provides default next/prev implementations for common operations.
00054 ///
00055 template<typename NodeTy>
00056 struct ilist_nextprev_traits {
00057   static NodeTy *getPrev(NodeTy *N) { return N->getPrev(); }
00058   static NodeTy *getNext(NodeTy *N) { return N->getNext(); }
00059   static const NodeTy *getPrev(const NodeTy *N) { return N->getPrev(); }
00060   static const NodeTy *getNext(const NodeTy *N) { return N->getNext(); }
00061 
00062   static void setPrev(NodeTy *N, NodeTy *Prev) { N->setPrev(Prev); }
00063   static void setNext(NodeTy *N, NodeTy *Next) { N->setNext(Next); }
00064 };
00065 
00066 template<typename NodeTy>
00067 struct ilist_traits;
00068 
00069 /// ilist_sentinel_traits - A fragment for template traits for intrusive list
00070 /// that provides default sentinel implementations for common operations.
00071 ///
00072 /// ilist_sentinel_traits implements a lazy dynamic sentinel allocation
00073 /// strategy. The sentinel is stored in the prev field of ilist's Head.
00074 ///
00075 template<typename NodeTy>
00076 struct ilist_sentinel_traits {
00077   /// createSentinel - create the dynamic sentinel
00078   static NodeTy *createSentinel() { return new NodeTy(); }
00079 
00080   /// destroySentinel - deallocate the dynamic sentinel
00081   static void destroySentinel(NodeTy *N) { delete N; }
00082 
00083   /// provideInitialHead - when constructing an ilist, provide a starting
00084   /// value for its Head
00085   /// @return null node to indicate that it needs to be allocated later
00086   static NodeTy *provideInitialHead() { return nullptr; }
00087 
00088   /// ensureHead - make sure that Head is either already
00089   /// initialized or assigned a fresh sentinel
00090   /// @return the sentinel
00091   static NodeTy *ensureHead(NodeTy *&Head) {
00092     if (!Head) {
00093       Head = ilist_traits<NodeTy>::createSentinel();
00094       ilist_traits<NodeTy>::noteHead(Head, Head);
00095       ilist_traits<NodeTy>::setNext(Head, nullptr);
00096       return Head;
00097     }
00098     return ilist_traits<NodeTy>::getPrev(Head);
00099   }
00100 
00101   /// noteHead - stash the sentinel into its default location
00102   static void noteHead(NodeTy *NewHead, NodeTy *Sentinel) {
00103     ilist_traits<NodeTy>::setPrev(NewHead, Sentinel);
00104   }
00105 };
00106 
00107 /// ilist_node_traits - A fragment for template traits for intrusive list
00108 /// that provides default node related operations.
00109 ///
00110 template<typename NodeTy>
00111 struct ilist_node_traits {
00112   static NodeTy *createNode(const NodeTy &V) { return new NodeTy(V); }
00113   static void deleteNode(NodeTy *V) { delete V; }
00114 
00115   void addNodeToList(NodeTy *) {}
00116   void removeNodeFromList(NodeTy *) {}
00117   void transferNodesFromList(ilist_node_traits &    /*SrcTraits*/,
00118                              ilist_iterator<NodeTy> /*first*/,
00119                              ilist_iterator<NodeTy> /*last*/) {}
00120 };
00121 
00122 /// ilist_default_traits - Default template traits for intrusive list.
00123 /// By inheriting from this, you can easily use default implementations
00124 /// for all common operations.
00125 ///
00126 template<typename NodeTy>
00127 struct ilist_default_traits : public ilist_nextprev_traits<NodeTy>,
00128                               public ilist_sentinel_traits<NodeTy>,
00129                               public ilist_node_traits<NodeTy> {
00130 };
00131 
00132 // Template traits for intrusive list.  By specializing this template class, you
00133 // can change what next/prev fields are used to store the links...
00134 template<typename NodeTy>
00135 struct ilist_traits : public ilist_default_traits<NodeTy> {};
00136 
00137 // Const traits are the same as nonconst traits...
00138 template<typename Ty>
00139 struct ilist_traits<const Ty> : public ilist_traits<Ty> {};
00140 
00141 //===----------------------------------------------------------------------===//
00142 // ilist_iterator<Node> - Iterator for intrusive list.
00143 //
00144 template<typename NodeTy>
00145 class ilist_iterator
00146   : public std::iterator<std::bidirectional_iterator_tag, NodeTy, ptrdiff_t> {
00147 
00148 public:
00149   typedef ilist_traits<NodeTy> Traits;
00150   typedef std::iterator<std::bidirectional_iterator_tag,
00151                         NodeTy, ptrdiff_t> super;
00152 
00153   typedef typename super::value_type value_type;
00154   typedef typename super::difference_type difference_type;
00155   typedef typename super::pointer pointer;
00156   typedef typename super::reference reference;
00157 private:
00158   pointer NodePtr;
00159 
00160   // ilist_iterator is not a random-access iterator, but it has an
00161   // implicit conversion to pointer-type, which is. Declare (but
00162   // don't define) these functions as private to help catch
00163   // accidental misuse.
00164   void operator[](difference_type) const;
00165   void operator+(difference_type) const;
00166   void operator-(difference_type) const;
00167   void operator+=(difference_type) const;
00168   void operator-=(difference_type) const;
00169   template<class T> void operator<(T) const;
00170   template<class T> void operator<=(T) const;
00171   template<class T> void operator>(T) const;
00172   template<class T> void operator>=(T) const;
00173   template<class T> void operator-(T) const;
00174 public:
00175 
00176   ilist_iterator(pointer NP) : NodePtr(NP) {}
00177   ilist_iterator(reference NR) : NodePtr(&NR) {}
00178   ilist_iterator() : NodePtr(nullptr) {}
00179 
00180   // This is templated so that we can allow constructing a const iterator from
00181   // a nonconst iterator...
00182   template<class node_ty>
00183   ilist_iterator(const ilist_iterator<node_ty> &RHS)
00184     : NodePtr(RHS.getNodePtrUnchecked()) {}
00185 
00186   // This is templated so that we can allow assigning to a const iterator from
00187   // a nonconst iterator...
00188   template<class node_ty>
00189   const ilist_iterator &operator=(const ilist_iterator<node_ty> &RHS) {
00190     NodePtr = RHS.getNodePtrUnchecked();
00191     return *this;
00192   }
00193 
00194   // Accessors...
00195   operator pointer() const {
00196     return NodePtr;
00197   }
00198 
00199   reference operator*() const {
00200     return *NodePtr;
00201   }
00202   pointer operator->() const { return &operator*(); }
00203 
00204   // Comparison operators
00205   bool operator==(const ilist_iterator &RHS) const {
00206     return NodePtr == RHS.NodePtr;
00207   }
00208   bool operator!=(const ilist_iterator &RHS) const {
00209     return NodePtr != RHS.NodePtr;
00210   }
00211 
00212   // Increment and decrement operators...
00213   ilist_iterator &operator--() {      // predecrement - Back up
00214     NodePtr = Traits::getPrev(NodePtr);
00215     assert(NodePtr && "--'d off the beginning of an ilist!");
00216     return *this;
00217   }
00218   ilist_iterator &operator++() {      // preincrement - Advance
00219     NodePtr = Traits::getNext(NodePtr);
00220     return *this;
00221   }
00222   ilist_iterator operator--(int) {    // postdecrement operators...
00223     ilist_iterator tmp = *this;
00224     --*this;
00225     return tmp;
00226   }
00227   ilist_iterator operator++(int) {    // postincrement operators...
00228     ilist_iterator tmp = *this;
00229     ++*this;
00230     return tmp;
00231   }
00232 
00233   // Internal interface, do not use...
00234   pointer getNodePtrUnchecked() const { return NodePtr; }
00235 };
00236 
00237 // These are to catch errors when people try to use them as random access
00238 // iterators.
00239 template<typename T>
00240 void operator-(int, ilist_iterator<T>) LLVM_DELETED_FUNCTION;
00241 template<typename T>
00242 void operator-(ilist_iterator<T>,int) LLVM_DELETED_FUNCTION;
00243 
00244 template<typename T>
00245 void operator+(int, ilist_iterator<T>) LLVM_DELETED_FUNCTION;
00246 template<typename T>
00247 void operator+(ilist_iterator<T>,int) LLVM_DELETED_FUNCTION;
00248 
00249 // operator!=/operator== - Allow mixed comparisons without dereferencing
00250 // the iterator, which could very likely be pointing to end().
00251 template<typename T>
00252 bool operator!=(const T* LHS, const ilist_iterator<const T> &RHS) {
00253   return LHS != RHS.getNodePtrUnchecked();
00254 }
00255 template<typename T>
00256 bool operator==(const T* LHS, const ilist_iterator<const T> &RHS) {
00257   return LHS == RHS.getNodePtrUnchecked();
00258 }
00259 template<typename T>
00260 bool operator!=(T* LHS, const ilist_iterator<T> &RHS) {
00261   return LHS != RHS.getNodePtrUnchecked();
00262 }
00263 template<typename T>
00264 bool operator==(T* LHS, const ilist_iterator<T> &RHS) {
00265   return LHS == RHS.getNodePtrUnchecked();
00266 }
00267 
00268 
00269 // Allow ilist_iterators to convert into pointers to a node automatically when
00270 // used by the dyn_cast, cast, isa mechanisms...
00271 
00272 template<typename From> struct simplify_type;
00273 
00274 template<typename NodeTy> struct simplify_type<ilist_iterator<NodeTy> > {
00275   typedef NodeTy* SimpleType;
00276 
00277   static SimpleType getSimplifiedValue(ilist_iterator<NodeTy> &Node) {
00278     return &*Node;
00279   }
00280 };
00281 template<typename NodeTy> struct simplify_type<const ilist_iterator<NodeTy> > {
00282   typedef /*const*/ NodeTy* SimpleType;
00283 
00284   static SimpleType getSimplifiedValue(const ilist_iterator<NodeTy> &Node) {
00285     return &*Node;
00286   }
00287 };
00288 
00289 
00290 //===----------------------------------------------------------------------===//
00291 //
00292 /// iplist - The subset of list functionality that can safely be used on nodes
00293 /// of polymorphic types, i.e. a heterogeneous list with a common base class that
00294 /// holds the next/prev pointers.  The only state of the list itself is a single
00295 /// pointer to the head of the list.
00296 ///
00297 /// This list can be in one of three interesting states:
00298 /// 1. The list may be completely unconstructed.  In this case, the head
00299 ///    pointer is null.  When in this form, any query for an iterator (e.g.
00300 ///    begin() or end()) causes the list to transparently change to state #2.
00301 /// 2. The list may be empty, but contain a sentinel for the end iterator. This
00302 ///    sentinel is created by the Traits::createSentinel method and is a link
00303 ///    in the list.  When the list is empty, the pointer in the iplist points
00304 ///    to the sentinel.  Once the sentinel is constructed, it
00305 ///    is not destroyed until the list is.
00306 /// 3. The list may contain actual objects in it, which are stored as a doubly
00307 ///    linked list of nodes.  One invariant of the list is that the predecessor
00308 ///    of the first node in the list always points to the last node in the list,
00309 ///    and the successor pointer for the sentinel (which always stays at the
00310 ///    end of the list) is always null.
00311 ///
00312 template<typename NodeTy, typename Traits=ilist_traits<NodeTy> >
00313 class iplist : public Traits {
00314   mutable NodeTy *Head;
00315 
00316   // Use the prev node pointer of 'head' as the tail pointer.  This is really a
00317   // circularly linked list where we snip the 'next' link from the sentinel node
00318   // back to the first node in the list (to preserve assertions about going off
00319   // the end of the list).
00320   NodeTy *getTail() { return this->ensureHead(Head); }
00321   const NodeTy *getTail() const { return this->ensureHead(Head); }
00322   void setTail(NodeTy *N) const { this->noteHead(Head, N); }
00323 
00324   /// CreateLazySentinel - This method verifies whether the sentinel for the
00325   /// list has been created and lazily makes it if not.
00326   void CreateLazySentinel() const {
00327     this->ensureHead(Head);
00328   }
00329 
00330   static bool op_less(NodeTy &L, NodeTy &R) { return L < R; }
00331   static bool op_equal(NodeTy &L, NodeTy &R) { return L == R; }
00332 
00333   // No fundamental reason why iplist can't be copyable, but the default
00334   // copy/copy-assign won't do.
00335   iplist(const iplist &) LLVM_DELETED_FUNCTION;
00336   void operator=(const iplist &) LLVM_DELETED_FUNCTION;
00337 
00338 public:
00339   typedef NodeTy *pointer;
00340   typedef const NodeTy *const_pointer;
00341   typedef NodeTy &reference;
00342   typedef const NodeTy &const_reference;
00343   typedef NodeTy value_type;
00344   typedef ilist_iterator<NodeTy> iterator;
00345   typedef ilist_iterator<const NodeTy> const_iterator;
00346   typedef size_t size_type;
00347   typedef ptrdiff_t difference_type;
00348   typedef std::reverse_iterator<const_iterator>  const_reverse_iterator;
00349   typedef std::reverse_iterator<iterator>  reverse_iterator;
00350 
00351   iplist() : Head(this->provideInitialHead()) {}
00352   ~iplist() {
00353     if (!Head) return;
00354     clear();
00355     Traits::destroySentinel(getTail());
00356   }
00357 
00358   // Iterator creation methods.
00359   iterator begin() {
00360     CreateLazySentinel();
00361     return iterator(Head);
00362   }
00363   const_iterator begin() const {
00364     CreateLazySentinel();
00365     return const_iterator(Head);
00366   }
00367   iterator end() {
00368     CreateLazySentinel();
00369     return iterator(getTail());
00370   }
00371   const_iterator end() const {
00372     CreateLazySentinel();
00373     return const_iterator(getTail());
00374   }
00375 
00376   // reverse iterator creation methods.
00377   reverse_iterator rbegin()            { return reverse_iterator(end()); }
00378   const_reverse_iterator rbegin() const{ return const_reverse_iterator(end()); }
00379   reverse_iterator rend()              { return reverse_iterator(begin()); }
00380   const_reverse_iterator rend() const { return const_reverse_iterator(begin());}
00381 
00382 
00383   // Miscellaneous inspection routines.
00384   size_type max_size() const { return size_type(-1); }
00385   bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const {
00386     return !Head || Head == getTail();
00387   }
00388 
00389   // Front and back accessor functions...
00390   reference front() {
00391     assert(!empty() && "Called front() on empty list!");
00392     return *Head;
00393   }
00394   const_reference front() const {
00395     assert(!empty() && "Called front() on empty list!");
00396     return *Head;
00397   }
00398   reference back() {
00399     assert(!empty() && "Called back() on empty list!");
00400     return *this->getPrev(getTail());
00401   }
00402   const_reference back() const {
00403     assert(!empty() && "Called back() on empty list!");
00404     return *this->getPrev(getTail());
00405   }
00406 
00407   void swap(iplist &RHS) {
00408     assert(0 && "Swap does not use list traits callback correctly yet!");
00409     std::swap(Head, RHS.Head);
00410   }
00411 
00412   iterator insert(iterator where, NodeTy *New) {
00413     NodeTy *CurNode = where.getNodePtrUnchecked();
00414     NodeTy *PrevNode = this->getPrev(CurNode);
00415     this->setNext(New, CurNode);
00416     this->setPrev(New, PrevNode);
00417 
00418     if (CurNode != Head)  // Is PrevNode off the beginning of the list?
00419       this->setNext(PrevNode, New);
00420     else
00421       Head = New;
00422     this->setPrev(CurNode, New);
00423 
00424     this->addNodeToList(New);  // Notify traits that we added a node...
00425     return New;
00426   }
00427 
00428   iterator insertAfter(iterator where, NodeTy *New) {
00429     if (empty())
00430       return insert(begin(), New);
00431     else
00432       return insert(++where, New);
00433   }
00434 
00435   NodeTy *remove(iterator &IT) {
00436     assert(IT != end() && "Cannot remove end of list!");
00437     NodeTy *Node = &*IT;
00438     NodeTy *NextNode = this->getNext(Node);
00439     NodeTy *PrevNode = this->getPrev(Node);
00440 
00441     if (Node != Head)  // Is PrevNode off the beginning of the list?
00442       this->setNext(PrevNode, NextNode);
00443     else
00444       Head = NextNode;
00445     this->setPrev(NextNode, PrevNode);
00446     IT = NextNode;
00447     this->removeNodeFromList(Node);  // Notify traits that we removed a node...
00448 
00449     // Set the next/prev pointers of the current node to null.  This isn't
00450     // strictly required, but this catches errors where a node is removed from
00451     // an ilist (and potentially deleted) with iterators still pointing at it.
00452     // When those iterators are incremented or decremented, they will assert on
00453     // the null next/prev pointer instead of "usually working".
00454     this->setNext(Node, nullptr);
00455     this->setPrev(Node, nullptr);
00456     return Node;
00457   }
00458 
00459   NodeTy *remove(const iterator &IT) {
00460     iterator MutIt = IT;
00461     return remove(MutIt);
00462   }
00463 
00464   // erase - remove a node from the controlled sequence... and delete it.
00465   iterator erase(iterator where) {
00466     this->deleteNode(remove(where));
00467     return where;
00468   }
00469 
00470   /// Remove all nodes from the list like clear(), but do not call
00471   /// removeNodeFromList() or deleteNode().
00472   ///
00473   /// This should only be used immediately before freeing nodes in bulk to
00474   /// avoid traversing the list and bringing all the nodes into cache.
00475   void clearAndLeakNodesUnsafely() {
00476     if (Head) {
00477       Head = getTail();
00478       this->setPrev(Head, Head);
00479     }
00480   }
00481 
00482 private:
00483   // transfer - The heart of the splice function.  Move linked list nodes from
00484   // [first, last) into position.
00485   //
00486   void transfer(iterator position, iplist &L2, iterator first, iterator last) {
00487     assert(first != last && "Should be checked by callers");
00488     // Position cannot be contained in the range to be transferred.
00489     // Check for the most common mistake.
00490     assert(position != first &&
00491            "Insertion point can't be one of the transferred nodes");
00492 
00493     if (position != last) {
00494       // Note: we have to be careful about the case when we move the first node
00495       // in the list.  This node is the list sentinel node and we can't move it.
00496       NodeTy *ThisSentinel = getTail();
00497       setTail(nullptr);
00498       NodeTy *L2Sentinel = L2.getTail();
00499       L2.setTail(nullptr);
00500 
00501       // Remove [first, last) from its old position.
00502       NodeTy *First = &*first, *Prev = this->getPrev(First);
00503       NodeTy *Next = last.getNodePtrUnchecked(), *Last = this->getPrev(Next);
00504       if (Prev)
00505         this->setNext(Prev, Next);
00506       else
00507         L2.Head = Next;
00508       this->setPrev(Next, Prev);
00509 
00510       // Splice [first, last) into its new position.
00511       NodeTy *PosNext = position.getNodePtrUnchecked();
00512       NodeTy *PosPrev = this->getPrev(PosNext);
00513 
00514       // Fix head of list...
00515       if (PosPrev)
00516         this->setNext(PosPrev, First);
00517       else
00518         Head = First;
00519       this->setPrev(First, PosPrev);
00520 
00521       // Fix end of list...
00522       this->setNext(Last, PosNext);
00523       this->setPrev(PosNext, Last);
00524 
00525       this->transferNodesFromList(L2, First, PosNext);
00526 
00527       // Now that everything is set, restore the pointers to the list sentinels.
00528       L2.setTail(L2Sentinel);
00529       setTail(ThisSentinel);
00530     }
00531   }
00532 
00533 public:
00534 
00535   //===----------------------------------------------------------------------===
00536   // Functionality derived from other functions defined above...
00537   //
00538 
00539   size_type LLVM_ATTRIBUTE_UNUSED_RESULT size() const {
00540     if (!Head) return 0; // Don't require construction of sentinel if empty.
00541     return std::distance(begin(), end());
00542   }
00543 
00544   iterator erase(iterator first, iterator last) {
00545     while (first != last)
00546       first = erase(first);
00547     return last;
00548   }
00549 
00550   void clear() { if (Head) erase(begin(), end()); }
00551 
00552   // Front and back inserters...
00553   void push_front(NodeTy *val) { insert(begin(), val); }
00554   void push_back(NodeTy *val) { insert(end(), val); }
00555   void pop_front() {
00556     assert(!empty() && "pop_front() on empty list!");
00557     erase(begin());
00558   }
00559   void pop_back() {
00560     assert(!empty() && "pop_back() on empty list!");
00561     iterator t = end(); erase(--t);
00562   }
00563 
00564   // Special forms of insert...
00565   template<class InIt> void insert(iterator where, InIt first, InIt last) {
00566     for (; first != last; ++first) insert(where, *first);
00567   }
00568 
00569   // Splice members - defined in terms of transfer...
00570   void splice(iterator where, iplist &L2) {
00571     if (!L2.empty())
00572       transfer(where, L2, L2.begin(), L2.end());
00573   }
00574   void splice(iterator where, iplist &L2, iterator first) {
00575     iterator last = first; ++last;
00576     if (where == first || where == last) return; // No change
00577     transfer(where, L2, first, last);
00578   }
00579   void splice(iterator where, iplist &L2, iterator first, iterator last) {
00580     if (first != last) transfer(where, L2, first, last);
00581   }
00582 };
00583 
00584 
00585 template<typename NodeTy>
00586 struct ilist : public iplist<NodeTy> {
00587   typedef typename iplist<NodeTy>::size_type size_type;
00588   typedef typename iplist<NodeTy>::iterator iterator;
00589 
00590   ilist() {}
00591   ilist(const ilist &right) {
00592     insert(this->begin(), right.begin(), right.end());
00593   }
00594   explicit ilist(size_type count) {
00595     insert(this->begin(), count, NodeTy());
00596   }
00597   ilist(size_type count, const NodeTy &val) {
00598     insert(this->begin(), count, val);
00599   }
00600   template<class InIt> ilist(InIt first, InIt last) {
00601     insert(this->begin(), first, last);
00602   }
00603 
00604   // bring hidden functions into scope
00605   using iplist<NodeTy>::insert;
00606   using iplist<NodeTy>::push_front;
00607   using iplist<NodeTy>::push_back;
00608 
00609   // Main implementation here - Insert for a node passed by value...
00610   iterator insert(iterator where, const NodeTy &val) {
00611     return insert(where, this->createNode(val));
00612   }
00613 
00614 
00615   // Front and back inserters...
00616   void push_front(const NodeTy &val) { insert(this->begin(), val); }
00617   void push_back(const NodeTy &val) { insert(this->end(), val); }
00618 
00619   void insert(iterator where, size_type count, const NodeTy &val) {
00620     for (; count != 0; --count) insert(where, val);
00621   }
00622 
00623   // Assign special forms...
00624   void assign(size_type count, const NodeTy &val) {
00625     iterator I = this->begin();
00626     for (; I != this->end() && count != 0; ++I, --count)
00627       *I = val;
00628     if (count != 0)
00629       insert(this->end(), val, val);
00630     else
00631       erase(I, this->end());
00632   }
00633   template<class InIt> void assign(InIt first1, InIt last1) {
00634     iterator first2 = this->begin(), last2 = this->end();
00635     for ( ; first1 != last1 && first2 != last2; ++first1, ++first2)
00636       *first1 = *first2;
00637     if (first2 == last2)
00638       erase(first1, last1);
00639     else
00640       insert(last1, first2, last2);
00641   }
00642 
00643 
00644   // Resize members...
00645   void resize(size_type newsize, NodeTy val) {
00646     iterator i = this->begin();
00647     size_type len = 0;
00648     for ( ; i != this->end() && len < newsize; ++i, ++len) /* empty*/ ;
00649 
00650     if (len == newsize)
00651       erase(i, this->end());
00652     else                                          // i == end()
00653       insert(this->end(), newsize - len, val);
00654   }
00655   void resize(size_type newsize) { resize(newsize, NodeTy()); }
00656 };
00657 
00658 } // End llvm namespace
00659 
00660 namespace std {
00661   // Ensure that swap uses the fast list swap...
00662   template<class Ty>
00663   void swap(llvm::iplist<Ty> &Left, llvm::iplist<Ty> &Right) {
00664     Left.swap(Right);
00665   }
00666 }  // End 'std' extensions...
00667 
00668 #endif // LLVM_ADT_ILIST_H