aboutsummaryrefslogtreecommitdiff
path: root/src/list.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-05-11 22:04:29 +0000
committerMike Buland <eichlan@xagasoft.com>2011-05-11 22:04:29 +0000
commit166886978475125c86ae7a58ac9358cd52758d54 (patch)
tree38fb5a19f7d50ba8d3f994316eea94ab47b214ba /src/list.h
parent4f97cedf9abd647cdd6243d5526c7f776310cee8 (diff)
downloadlibbu++-166886978475125c86ae7a58ac9358cd52758d54.tar.gz
libbu++-166886978475125c86ae7a58ac9358cd52758d54.tar.bz2
libbu++-166886978475125c86ae7a58ac9358cd52758d54.tar.xz
libbu++-166886978475125c86ae7a58ac9358cd52758d54.zip
Tweaked the interface very slightly for insertSorted, very handy change.
Diffstat (limited to 'src/list.h')
-rw-r--r--src/list.h31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/list.h b/src/list.h
index c678d68..21ba0b5 100644
--- a/src/list.h
+++ b/src/list.h
@@ -59,7 +59,7 @@ namespace Bu
59 * Append a value to the list. 59 * Append a value to the list.
60 *@param v (const value_type &) The value to append. 60 *@param v (const value_type &) The value to append.
61 */ 61 */
62 void append( const value &v ) 62 Link *append( const value &v )
63 { 63 {
64 Link *pNew = la.allocate( 1 ); 64 Link *pNew = la.allocate( 1 );
65 pNew->pValue = va.allocate( 1 ); 65 pNew->pValue = va.allocate( 1 );
@@ -78,13 +78,14 @@ namespace Bu
78 pLast->pNext = pNew; 78 pLast->pNext = pNew;
79 pLast = pNew; 79 pLast = pNew;
80 } 80 }
81 return pNew;
81 } 82 }
82 83
83 /** 84 /**
84 * Prepend a value to the list. 85 * Prepend a value to the list.
85 *@param v (const value_type &) The value to prepend. 86 *@param v (const value_type &) The value to prepend.
86 */ 87 */
87 void prepend( const value &v ) 88 Link *prepend( const value &v )
88 { 89 {
89 Link *pNew = la.allocate( 1 ); 90 Link *pNew = la.allocate( 1 );
90 pNew->pValue = va.allocate( 1 ); 91 pNew->pValue = va.allocate( 1 );
@@ -103,6 +104,7 @@ namespace Bu
103 pFirst->pPrev = pNew; 104 pFirst->pPrev = pNew;
104 pFirst = pNew; 105 pFirst = pNew;
105 } 106 }
107 return pNew;
106 } 108 }
107 109
108 void clear() 110 void clear()
@@ -122,19 +124,17 @@ namespace Bu
122 nSize = 0; 124 nSize = 0;
123 } 125 }
124 126
125 void insert( Link *pLink, const value &v ) 127 Link *insert( Link *pLink, const value &v )
126 { 128 {
127 Link *pAfter = pLink; 129 Link *pAfter = pLink;
128 if( pAfter == NULL ) 130 if( pAfter == NULL )
129 { 131 {
130 append( v ); 132 return append( v );
131 return;
132 } 133 }
133 Link *pPrev = pAfter->pPrev; 134 Link *pPrev = pAfter->pPrev;
134 if( pPrev == NULL ) 135 if( pPrev == NULL )
135 { 136 {
136 prepend( v ); 137 return prepend( v );
137 return;
138 } 138 }
139 139
140 Link *pNew = la.allocate( 1 ); 140 Link *pNew = la.allocate( 1 );
@@ -146,6 +146,8 @@ namespace Bu
146 pNew->pPrev = pPrev; 146 pNew->pPrev = pPrev;
147 pAfter->pPrev = pNew; 147 pAfter->pPrev = pNew;
148 pPrev->pNext = pNew; 148 pPrev->pNext = pNew;
149
150 return pNew;
149 } 151 }
150 152
151 /** 153 /**
@@ -441,14 +443,13 @@ namespace Bu
441 * support the > operator. 443 * support the > operator.
442 */ 444 */
443 template<typename cmptype> 445 template<typename cmptype>
444 MyType &insertSorted( cmptype cmp, const value &v ) 446 iterator insertSorted( cmptype cmp, const value &v )
445 { 447 {
446 _hardCopy(); 448 _hardCopy();
447 if( core->pFirst == NULL ) 449 if( core->pFirst == NULL )
448 { 450 {
449 // Empty list 451 // Empty list
450 core->append( v ); 452 return iterator( core->append( v ) );
451 return *this;
452 } 453 }
453 else 454 else
454 { 455 {
@@ -457,26 +458,24 @@ namespace Bu
457 { 458 {
458 if( cmp( v, *(pCur->pValue)) ) 459 if( cmp( v, *(pCur->pValue)) )
459 { 460 {
460 core->insert( pCur, v ); 461 return iterator( core->insert( pCur, v ) );
461 return *this;
462 } 462 }
463 pCur = pCur->pNext; 463 pCur = pCur->pNext;
464 if( pCur == NULL ) 464 if( pCur == NULL )
465 { 465 {
466 core->append( v ); 466 return iterator( core->append( v ) );
467 return *this;
468 } 467 }
469 } 468 }
470 } 469 }
471 } 470 }
472 471
473 MyType &insertSorted( const value &v ) 472 iterator insertSorted( const value &v )
474 { 473 {
475 return insertSorted<__basicLTCmp<value> >( v ); 474 return insertSorted<__basicLTCmp<value> >( v );
476 } 475 }
477 476
478 template<typename cmptype> 477 template<typename cmptype>
479 MyType &insertSorted( const value &v ) 478 iterator insertSorted( const value &v )
480 { 479 {
481 cmptype cmp; 480 cmptype cmp;
482 return insertSorted( cmp, v ); 481 return insertSorted( cmp, v );