ilist.h revision 2600ca8b3f3602d0904289eeed3d26f3d7aad2ae
1//==-- llvm/ADT/ilist.h - Intrusive Linked List Template ---------*- C++ -*-==// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines classes to implement an intrusive doubly linked list class 11// (i.e. each node of the list must contain a next and previous field for the 12// list. 13// 14// The ilist_traits trait class is used to gain access to the next and previous 15// fields of the node type that the list is instantiated with. If it is not 16// specialized, the list defaults to using the getPrev(), getNext() method calls 17// to get the next and previous pointers. 18// 19// The ilist class itself, should be a plug in replacement for list, assuming 20// that the nodes contain next/prev pointers. This list replacement does not 21// provide a constant time size() method, so be careful to use empty() when you 22// really want to know if it's empty. 23// 24// The ilist class is implemented by allocating a 'tail' node when the list is 25// created (using ilist_traits<>::createSentinel()). This tail node is 26// absolutely required because the user must be able to compute end()-1. Because 27// of this, users of the direct next/prev links will see an extra link on the 28// end of the list, which should be ignored. 29// 30// Requirements for a user of this list: 31// 32// 1. The user must provide {g|s}et{Next|Prev} methods, or specialize 33// ilist_traits to provide an alternate way of getting and setting next and 34// prev links. 35// 36//===----------------------------------------------------------------------===// 37 38#ifndef LLVM_ADT_ILIST_H 39#define LLVM_ADT_ILIST_H 40 41#include "llvm/ADT/iterator.h" 42#include <cassert> 43 44#undef LLVM_COMPACTIFY_SENTINELS 45/// @brief activate small sentinel structs 46/// Comment out if you want better debuggability 47/// of ilist<> end() iterators. 48/// See also llvm/ADT/ilist_node.h, where the 49/// same change must be made. 50/// 51#define LLVM_COMPACTIFY_SENTINELS 1 52 53#if defined(LLVM_COMPACTIFY_SENTINELS) && LLVM_COMPACTIFY_SENTINELS 54# define sentinel_tail_assert(COND) 55#else 56# define sentinel_tail_assert(COND) assert(COND) 57#endif 58 59namespace llvm { 60 61template<typename NodeTy, typename Traits> class iplist; 62template<typename NodeTy> class ilist_iterator; 63 64/// ilist_nextprev_traits - A fragment for template traits for intrusive list 65/// that provides default next/prev implementations for common operations. 66/// 67template<typename NodeTy> 68struct ilist_nextprev_traits { 69 static NodeTy *getPrev(NodeTy *N) { return N->getPrev(); } 70 static NodeTy *getNext(NodeTy *N) { return N->getNext(); } 71 static const NodeTy *getPrev(const NodeTy *N) { return N->getPrev(); } 72 static const NodeTy *getNext(const NodeTy *N) { return N->getNext(); } 73 74 static void setPrev(NodeTy *N, NodeTy *Prev) { N->setPrev(Prev); } 75 static void setNext(NodeTy *N, NodeTy *Next) { N->setNext(Next); } 76}; 77 78template<typename NodeTy> 79struct ilist_traits; 80 81/// ilist_sentinel_traits - A fragment for template traits for intrusive list 82/// that provides default sentinel implementations for common operations. 83/// 84/// ilist_sentinel_traits implements a lazy dynamic sentinel allocation 85/// strategy. The sentinel is stored in the prev field of ilist's Head. 86/// 87template<typename NodeTy> 88struct ilist_sentinel_traits { 89 /// createSentinel - create the dynamic sentinel 90 static NodeTy *createSentinel() { return new NodeTy(); } 91 92 /// destroySentinel - deallocate the dynamic sentinel 93 static void destroySentinel(NodeTy *N) { delete N; } 94 95 /// provideInitialHead - when constructing an ilist, provide a starting 96 /// value for its Head 97 /// @return null node to indicate that it needs to be allocated later 98 static NodeTy *provideInitialHead() { return 0; } 99 100 /// ensureHead - make sure that Head is either already 101 /// initialized or assigned a fresh sentinel 102 /// @return the sentinel 103 static NodeTy *ensureHead(NodeTy *&Head) { 104 if (!Head) { 105 Head = ilist_traits<NodeTy>::createSentinel(); 106 ilist_traits<NodeTy>::noteHead(Head, Head); 107 ilist_traits<NodeTy>::setNext(Head, 0); 108 return Head; 109 } 110 return ilist_traits<NodeTy>::getPrev(Head); 111 } 112 113 /// noteHead - stash the sentinel into its default location 114 static void noteHead(NodeTy *NewHead, NodeTy *Sentinel) { 115 ilist_traits<NodeTy>::setPrev(NewHead, Sentinel); 116 } 117}; 118 119/// ilist_node_traits - A fragment for template traits for intrusive list 120/// that provides default node related operations. 121/// 122template<typename NodeTy> 123struct ilist_node_traits { 124 static NodeTy *createNode(const NodeTy &V) { return new NodeTy(V); } 125 static void deleteNode(NodeTy *V) { delete V; } 126 127 void addNodeToList(NodeTy *) {} 128 void removeNodeFromList(NodeTy *) {} 129 void transferNodesFromList(ilist_node_traits & /*SrcTraits*/, 130 ilist_iterator<NodeTy> /*first*/, 131 ilist_iterator<NodeTy> /*last*/) {} 132}; 133 134/// ilist_default_traits - Default template traits for intrusive list. 135/// By inheriting from this, you can easily use default implementations 136/// for all common operations. 137/// 138template<typename NodeTy> 139struct ilist_default_traits : ilist_nextprev_traits<NodeTy>, 140 ilist_sentinel_traits<NodeTy>, 141 ilist_node_traits<NodeTy> { 142}; 143 144// Template traits for intrusive list. By specializing this template class, you 145// can change what next/prev fields are used to store the links... 146template<typename NodeTy> 147struct ilist_traits : ilist_default_traits<NodeTy> {}; 148 149// Const traits are the same as nonconst traits... 150template<typename Ty> 151struct ilist_traits<const Ty> : public ilist_traits<Ty> {}; 152 153//===----------------------------------------------------------------------===// 154// ilist_iterator<Node> - Iterator for intrusive list. 155// 156template<typename NodeTy> 157class ilist_iterator 158 : public bidirectional_iterator<NodeTy, ptrdiff_t> { 159 160public: 161 typedef ilist_traits<NodeTy> Traits; 162 typedef bidirectional_iterator<NodeTy, ptrdiff_t> super; 163 164 typedef typename super::value_type value_type; 165 typedef typename super::difference_type difference_type; 166 typedef typename super::pointer pointer; 167 typedef typename super::reference reference; 168private: 169 pointer NodePtr; 170 171 // ilist_iterator is not a random-access iterator, but it has an 172 // implicit conversion to pointer-type, which is. Declare (but 173 // don't define) these functions as private to help catch 174 // accidental misuse. 175 void operator[](difference_type) const; 176 void operator+(difference_type) const; 177 void operator-(difference_type) const; 178 void operator+=(difference_type) const; 179 void operator-=(difference_type) const; 180 template<class T> void operator<(T) const; 181 template<class T> void operator<=(T) const; 182 template<class T> void operator>(T) const; 183 template<class T> void operator>=(T) const; 184 template<class T> void operator-(T) const; 185public: 186 187 ilist_iterator(pointer NP) : NodePtr(NP) {} 188 ilist_iterator(reference NR) : NodePtr(&NR) {} 189 ilist_iterator() : NodePtr(0) {} 190 191 // This is templated so that we can allow constructing a const iterator from 192 // a nonconst iterator... 193 template<class node_ty> 194 ilist_iterator(const ilist_iterator<node_ty> &RHS) 195 : NodePtr(RHS.getNodePtrUnchecked()) {} 196 197 // This is templated so that we can allow assigning to a const iterator from 198 // a nonconst iterator... 199 template<class node_ty> 200 const ilist_iterator &operator=(const ilist_iterator<node_ty> &RHS) { 201 NodePtr = RHS.getNodePtrUnchecked(); 202 return *this; 203 } 204 205 // Accessors... 206 operator pointer() const { 207 sentinel_tail_assert(Traits::getNext(NodePtr) != 0 && "Dereferencing end()!"); 208 return NodePtr; 209 } 210 211 reference operator*() const { 212 sentinel_tail_assert(Traits::getNext(NodePtr) != 0 && "Dereferencing end()!"); 213 return *NodePtr; 214 } 215 pointer operator->() const { return &operator*(); } 216 217 // Comparison operators 218 bool operator==(const ilist_iterator &RHS) const { 219 return NodePtr == RHS.NodePtr; 220 } 221 bool operator!=(const ilist_iterator &RHS) const { 222 return NodePtr != RHS.NodePtr; 223 } 224 225 // Increment and decrement operators... 226 ilist_iterator &operator--() { // predecrement - Back up 227 NodePtr = Traits::getPrev(NodePtr); 228 assert(NodePtr && "--'d off the beginning of an ilist!"); 229 return *this; 230 } 231 ilist_iterator &operator++() { // preincrement - Advance 232 NodePtr = Traits::getNext(NodePtr); 233 sentinel_tail_assert(NodePtr && "++'d off the end of an ilist!"); 234 return *this; 235 } 236 ilist_iterator operator--(int) { // postdecrement operators... 237 ilist_iterator tmp = *this; 238 --*this; 239 return tmp; 240 } 241 ilist_iterator operator++(int) { // postincrement operators... 242 ilist_iterator tmp = *this; 243 ++*this; 244 return tmp; 245 } 246 247 // Internal interface, do not use... 248 pointer getNodePtrUnchecked() const { return NodePtr; } 249}; 250 251// do not implement. this is to catch errors when people try to use 252// them as random access iterators 253template<typename T> 254void operator-(int, ilist_iterator<T>); 255template<typename T> 256void operator-(ilist_iterator<T>,int); 257 258template<typename T> 259void operator+(int, ilist_iterator<T>); 260template<typename T> 261void operator+(ilist_iterator<T>,int); 262 263// operator!=/operator== - Allow mixed comparisons without dereferencing 264// the iterator, which could very likely be pointing to end(). 265template<typename T> 266bool operator!=(const T* LHS, const ilist_iterator<const T> &RHS) { 267 return LHS != RHS.getNodePtrUnchecked(); 268} 269template<typename T> 270bool operator==(const T* LHS, const ilist_iterator<const T> &RHS) { 271 return LHS == RHS.getNodePtrUnchecked(); 272} 273template<typename T> 274bool operator!=(T* LHS, const ilist_iterator<T> &RHS) { 275 return LHS != RHS.getNodePtrUnchecked(); 276} 277template<typename T> 278bool operator==(T* LHS, const ilist_iterator<T> &RHS) { 279 return LHS == RHS.getNodePtrUnchecked(); 280} 281 282 283// Allow ilist_iterators to convert into pointers to a node automatically when 284// used by the dyn_cast, cast, isa mechanisms... 285 286template<typename From> struct simplify_type; 287 288template<typename NodeTy> struct simplify_type<ilist_iterator<NodeTy> > { 289 typedef NodeTy* SimpleType; 290 291 static SimpleType getSimplifiedValue(const ilist_iterator<NodeTy> &Node) { 292 return &*Node; 293 } 294}; 295template<typename NodeTy> struct simplify_type<const ilist_iterator<NodeTy> > { 296 typedef NodeTy* SimpleType; 297 298 static SimpleType getSimplifiedValue(const ilist_iterator<NodeTy> &Node) { 299 return &*Node; 300 } 301}; 302 303 304//===----------------------------------------------------------------------===// 305// 306/// iplist - The subset of list functionality that can safely be used on nodes 307/// of polymorphic types, i.e. a heterogenous list with a common base class that 308/// holds the next/prev pointers. The only state of the list itself is a single 309/// pointer to the head of the list. 310/// 311/// This list can be in one of three interesting states: 312/// 1. The list may be completely unconstructed. In this case, the head 313/// pointer is null. When in this form, any query for an iterator (e.g. 314/// begin() or end()) causes the list to transparently change to state #2. 315/// 2. The list may be empty, but contain a sentinel for the end iterator. This 316/// sentinel is created by the Traits::createSentinel method and is a link 317/// in the list. When the list is empty, the pointer in the iplist points 318/// to the sentinel. Once the sentinel is constructed, it 319/// is not destroyed until the list is. 320/// 3. The list may contain actual objects in it, which are stored as a doubly 321/// linked list of nodes. One invariant of the list is that the predecessor 322/// of the first node in the list always points to the last node in the list, 323/// and the successor pointer for the sentinel (which always stays at the 324/// end of the list) is always null. 325/// 326template<typename NodeTy, typename Traits=ilist_traits<NodeTy> > 327class iplist : public Traits { 328 mutable NodeTy *Head; 329 330 // Use the prev node pointer of 'head' as the tail pointer. This is really a 331 // circularly linked list where we snip the 'next' link from the sentinel node 332 // back to the first node in the list (to preserve assertions about going off 333 // the end of the list). 334 NodeTy *getTail() { return this->ensureHead(Head); } 335 const NodeTy *getTail() const { return this->ensureHead(Head); } 336 void setTail(NodeTy *N) const { this->noteHead(Head, N); } 337 338 /// CreateLazySentinel - This method verifies whether the sentinel for the 339 /// list has been created and lazily makes it if not. 340 void CreateLazySentinel() const { 341 this->ensureHead(Head); 342 } 343 344 static bool op_less(NodeTy &L, NodeTy &R) { return L < R; } 345 static bool op_equal(NodeTy &L, NodeTy &R) { return L == R; } 346 347 // No fundamental reason why iplist can't be copyable, but the default 348 // copy/copy-assign won't do. 349 iplist(const iplist &); // do not implement 350 void operator=(const iplist &); // do not implement 351 352public: 353 typedef NodeTy *pointer; 354 typedef const NodeTy *const_pointer; 355 typedef NodeTy &reference; 356 typedef const NodeTy &const_reference; 357 typedef NodeTy value_type; 358 typedef ilist_iterator<NodeTy> iterator; 359 typedef ilist_iterator<const NodeTy> const_iterator; 360 typedef size_t size_type; 361 typedef ptrdiff_t difference_type; 362 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 363 typedef std::reverse_iterator<iterator> reverse_iterator; 364 365 iplist() : Head(this->provideInitialHead()) {} 366 ~iplist() { 367 if (!Head) return; 368 clear(); 369 Traits::destroySentinel(getTail()); 370 } 371 372 // Iterator creation methods. 373 iterator begin() { 374 CreateLazySentinel(); 375 return iterator(Head); 376 } 377 const_iterator begin() const { 378 CreateLazySentinel(); 379 return const_iterator(Head); 380 } 381 iterator end() { 382 CreateLazySentinel(); 383 return iterator(getTail()); 384 } 385 const_iterator end() const { 386 CreateLazySentinel(); 387 return const_iterator(getTail()); 388 } 389 390 // reverse iterator creation methods. 391 reverse_iterator rbegin() { return reverse_iterator(end()); } 392 const_reverse_iterator rbegin() const{ return const_reverse_iterator(end()); } 393 reverse_iterator rend() { return reverse_iterator(begin()); } 394 const_reverse_iterator rend() const { return const_reverse_iterator(begin());} 395 396 397 // Miscellaneous inspection routines. 398 size_type max_size() const { return size_type(-1); } 399 bool empty() const { return Head == 0 || Head == getTail(); } 400 401 // Front and back accessor functions... 402 reference front() { 403 assert(!empty() && "Called front() on empty list!"); 404 return *Head; 405 } 406 const_reference front() const { 407 assert(!empty() && "Called front() on empty list!"); 408 return *Head; 409 } 410 reference back() { 411 assert(!empty() && "Called back() on empty list!"); 412 return *this->getPrev(getTail()); 413 } 414 const_reference back() const { 415 assert(!empty() && "Called back() on empty list!"); 416 return *this->getPrev(getTail()); 417 } 418 419 void swap(iplist &RHS) { 420 assert(0 && "Swap does not use list traits callback correctly yet!"); 421 std::swap(Head, RHS.Head); 422 } 423 424 iterator insert(iterator where, NodeTy *New) { 425 NodeTy *CurNode = where.getNodePtrUnchecked(); 426 NodeTy *PrevNode = this->getPrev(CurNode); 427 this->setNext(New, CurNode); 428 this->setPrev(New, PrevNode); 429 430 if (CurNode != Head) // Is PrevNode off the beginning of the list? 431 this->setNext(PrevNode, New); 432 else 433 Head = New; 434 this->setPrev(CurNode, New); 435 436 this->addNodeToList(New); // Notify traits that we added a node... 437 return New; 438 } 439 440 iterator insertAfter(iterator where, NodeTy *New) { 441 if (empty()) 442 return insert(begin(), New); 443 else 444 return insert(++where, New); 445 } 446 447 NodeTy *remove(iterator &IT) { 448 assert(IT != end() && "Cannot remove end of list!"); 449 NodeTy *Node = &*IT; 450 NodeTy *NextNode = this->getNext(Node); 451 NodeTy *PrevNode = this->getPrev(Node); 452 453 if (Node != Head) // Is PrevNode off the beginning of the list? 454 this->setNext(PrevNode, NextNode); 455 else 456 Head = NextNode; 457 this->setPrev(NextNode, PrevNode); 458 IT = NextNode; 459 this->removeNodeFromList(Node); // Notify traits that we removed a node... 460 461 // Set the next/prev pointers of the current node to null. This isn't 462 // strictly required, but this catches errors where a node is removed from 463 // an ilist (and potentially deleted) with iterators still pointing at it. 464 // When those iterators are incremented or decremented, they will assert on 465 // the null next/prev pointer instead of "usually working". 466 this->setNext(Node, 0); 467 this->setPrev(Node, 0); 468 return Node; 469 } 470 471 NodeTy *remove(const iterator &IT) { 472 iterator MutIt = IT; 473 return remove(MutIt); 474 } 475 476 // erase - remove a node from the controlled sequence... and delete it. 477 iterator erase(iterator where) { 478 this->deleteNode(remove(where)); 479 return where; 480 } 481 482 483private: 484 // transfer - The heart of the splice function. Move linked list nodes from 485 // [first, last) into position. 486 // 487 void transfer(iterator position, iplist &L2, iterator first, iterator last) { 488 assert(first != last && "Should be checked by callers"); 489 490 if (position != last) { 491 // Note: we have to be careful about the case when we move the first node 492 // in the list. This node is the list sentinel node and we can't move it. 493 NodeTy *ThisSentinel = getTail(); 494 setTail(0); 495 NodeTy *L2Sentinel = L2.getTail(); 496 L2.setTail(0); 497 498 // Remove [first, last) from its old position. 499 NodeTy *First = &*first, *Prev = this->getPrev(First); 500 NodeTy *Next = last.getNodePtrUnchecked(), *Last = this->getPrev(Next); 501 if (Prev) 502 this->setNext(Prev, Next); 503 else 504 L2.Head = Next; 505 this->setPrev(Next, Prev); 506 507 // Splice [first, last) into its new position. 508 NodeTy *PosNext = position.getNodePtrUnchecked(); 509 NodeTy *PosPrev = this->getPrev(PosNext); 510 511 // Fix head of list... 512 if (PosPrev) 513 this->setNext(PosPrev, First); 514 else 515 Head = First; 516 this->setPrev(First, PosPrev); 517 518 // Fix end of list... 519 this->setNext(Last, PosNext); 520 this->setPrev(PosNext, Last); 521 522 this->transferNodesFromList(L2, First, PosNext); 523 524 // Now that everything is set, restore the pointers to the list sentinels. 525 L2.setTail(L2Sentinel); 526 setTail(ThisSentinel); 527 } 528 } 529 530public: 531 532 //===----------------------------------------------------------------------=== 533 // Functionality derived from other functions defined above... 534 // 535 536 size_type size() const { 537 if (Head == 0) return 0; // Don't require construction of sentinel if empty. 538 return std::distance(begin(), end()); 539 } 540 541 iterator erase(iterator first, iterator last) { 542 while (first != last) 543 first = erase(first); 544 return last; 545 } 546 547 void clear() { if (Head) erase(begin(), end()); } 548 549 // Front and back inserters... 550 void push_front(NodeTy *val) { insert(begin(), val); } 551 void push_back(NodeTy *val) { insert(end(), val); } 552 void pop_front() { 553 assert(!empty() && "pop_front() on empty list!"); 554 erase(begin()); 555 } 556 void pop_back() { 557 assert(!empty() && "pop_back() on empty list!"); 558 iterator t = end(); erase(--t); 559 } 560 561 // Special forms of insert... 562 template<class InIt> void insert(iterator where, InIt first, InIt last) { 563 for (; first != last; ++first) insert(where, *first); 564 } 565 566 // Splice members - defined in terms of transfer... 567 void splice(iterator where, iplist &L2) { 568 if (!L2.empty()) 569 transfer(where, L2, L2.begin(), L2.end()); 570 } 571 void splice(iterator where, iplist &L2, iterator first) { 572 iterator last = first; ++last; 573 if (where == first || where == last) return; // No change 574 transfer(where, L2, first, last); 575 } 576 void splice(iterator where, iplist &L2, iterator first, iterator last) { 577 if (first != last) transfer(where, L2, first, last); 578 } 579 580 581 582 //===----------------------------------------------------------------------=== 583 // High-Level Functionality that shouldn't really be here, but is part of list 584 // 585 586 // These two functions are actually called remove/remove_if in list<>, but 587 // they actually do the job of erase, rename them accordingly. 588 // 589 void erase(const NodeTy &val) { 590 for (iterator I = begin(), E = end(); I != E; ) { 591 iterator next = I; ++next; 592 if (*I == val) erase(I); 593 I = next; 594 } 595 } 596 template<class Pr1> void erase_if(Pr1 pred) { 597 for (iterator I = begin(), E = end(); I != E; ) { 598 iterator next = I; ++next; 599 if (pred(*I)) erase(I); 600 I = next; 601 } 602 } 603 604 template<class Pr2> void unique(Pr2 pred) { 605 if (empty()) return; 606 for (iterator I = begin(), E = end(), Next = begin(); ++Next != E;) { 607 if (pred(*I)) 608 erase(Next); 609 else 610 I = Next; 611 Next = I; 612 } 613 } 614 void unique() { unique(op_equal); } 615 616 template<class Pr3> void merge(iplist &right, Pr3 pred) { 617 iterator first1 = begin(), last1 = end(); 618 iterator first2 = right.begin(), last2 = right.end(); 619 while (first1 != last1 && first2 != last2) 620 if (pred(*first2, *first1)) { 621 iterator next = first2; 622 transfer(first1, right, first2, ++next); 623 first2 = next; 624 } else { 625 ++first1; 626 } 627 if (first2 != last2) transfer(last1, right, first2, last2); 628 } 629 void merge(iplist &right) { return merge(right, op_less); } 630 631 template<class Pr3> void sort(Pr3 pred); 632 void sort() { sort(op_less); } 633 void reverse(); 634}; 635 636 637template<typename NodeTy> 638struct ilist : public iplist<NodeTy> { 639 typedef typename iplist<NodeTy>::size_type size_type; 640 typedef typename iplist<NodeTy>::iterator iterator; 641 642 ilist() {} 643 ilist(const ilist &right) { 644 insert(this->begin(), right.begin(), right.end()); 645 } 646 explicit ilist(size_type count) { 647 insert(this->begin(), count, NodeTy()); 648 } 649 ilist(size_type count, const NodeTy &val) { 650 insert(this->begin(), count, val); 651 } 652 template<class InIt> ilist(InIt first, InIt last) { 653 insert(this->begin(), first, last); 654 } 655 656 // bring hidden functions into scope 657 using iplist<NodeTy>::insert; 658 using iplist<NodeTy>::push_front; 659 using iplist<NodeTy>::push_back; 660 661 // Main implementation here - Insert for a node passed by value... 662 iterator insert(iterator where, const NodeTy &val) { 663 return insert(where, createNode(val)); 664 } 665 666 667 // Front and back inserters... 668 void push_front(const NodeTy &val) { insert(this->begin(), val); } 669 void push_back(const NodeTy &val) { insert(this->end(), val); } 670 671 // Special forms of insert... 672 template<class InIt> void insert(iterator where, InIt first, InIt last) { 673 for (; first != last; ++first) insert(where, *first); 674 } 675 void insert(iterator where, size_type count, const NodeTy &val) { 676 for (; count != 0; --count) insert(where, val); 677 } 678 679 // Assign special forms... 680 void assign(size_type count, const NodeTy &val) { 681 iterator I = this->begin(); 682 for (; I != this->end() && count != 0; ++I, --count) 683 *I = val; 684 if (count != 0) 685 insert(this->end(), val, val); 686 else 687 erase(I, this->end()); 688 } 689 template<class InIt> void assign(InIt first1, InIt last1) { 690 iterator first2 = this->begin(), last2 = this->end(); 691 for ( ; first1 != last1 && first2 != last2; ++first1, ++first2) 692 *first1 = *first2; 693 if (first2 == last2) 694 erase(first1, last1); 695 else 696 insert(last1, first2, last2); 697 } 698 699 700 // Resize members... 701 void resize(size_type newsize, NodeTy val) { 702 iterator i = this->begin(); 703 size_type len = 0; 704 for ( ; i != this->end() && len < newsize; ++i, ++len) /* empty*/ ; 705 706 if (len == newsize) 707 erase(i, this->end()); 708 else // i == end() 709 insert(this->end(), newsize - len, val); 710 } 711 void resize(size_type newsize) { resize(newsize, NodeTy()); } 712}; 713 714} // End llvm namespace 715 716namespace std { 717 // Ensure that swap uses the fast list swap... 718 template<class Ty> 719 void swap(llvm::iplist<Ty> &Left, llvm::iplist<Ty> &Right) { 720 Left.swap(Right); 721 } 722} // End 'std' extensions... 723 724#endif // LLVM_ADT_ILIST_H 725