 |
Changeset 3669
- Timestamp:
- 06/23/08 03:24:26
(3 months ago)
- Author:
- kris
- Message:
isolated simple remove/replace methods
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r3600 |
r3669 |
|
| 231 | 231 | ***********************************************************************/ |
|---|
| 232 | 232 | |
|---|
| 233 | | final uint remove (V element, bool all=false) |
|---|
| | 233 | final uint remove (V element, bool all) |
|---|
| | 234 | { |
|---|
| | 235 | return remove(element) ? 1 : 0; |
|---|
| | 236 | } |
|---|
| | 237 | |
|---|
| | 238 | /*********************************************************************** |
|---|
| | 239 | |
|---|
| | 240 | Remove the provided element. Returns true if found, false |
|---|
| | 241 | otherwise |
|---|
| | 242 | |
|---|
| | 243 | Time complexity: O(1) average; O(n) worst |
|---|
| | 244 | |
|---|
| | 245 | ***********************************************************************/ |
|---|
| | 246 | |
|---|
| | 247 | final bool remove (V element) |
|---|
| 234 | 248 | { |
|---|
| 235 | 249 | if (count) |
|---|
| … | … | |
| 253 | 267 | else |
|---|
| 254 | 268 | trail.next = n; |
|---|
| 255 | | return 1; |
|---|
| | 269 | return true; |
|---|
| 256 | 270 | } |
|---|
| 257 | 271 | else |
|---|
| … | … | |
| 262 | 276 | } |
|---|
| 263 | 277 | } |
|---|
| 264 | | return 0; |
|---|
| | 278 | return false; |
|---|
| 265 | 279 | } |
|---|
| 266 | 280 | |
|---|
| … | … | |
| 273 | 287 | ***********************************************************************/ |
|---|
| 274 | 288 | |
|---|
| 275 | | final uint replace (V oldElement, V newElement, bool all=false) |
|---|
| | 289 | final uint replace (V oldElement, V newElement, bool all) |
|---|
| | 290 | { |
|---|
| | 291 | return replace (oldElement, newElement) ? 1 : 0; |
|---|
| | 292 | } |
|---|
| | 293 | |
|---|
| | 294 | /*********************************************************************** |
|---|
| | 295 | |
|---|
| | 296 | Replace the first instance of oldElement with newElement. |
|---|
| | 297 | Returns true if oldElement was found and replaced, false |
|---|
| | 298 | otherwise. |
|---|
| | 299 | |
|---|
| | 300 | ***********************************************************************/ |
|---|
| | 301 | |
|---|
| | 302 | final bool replace (V oldElement, V newElement) |
|---|
| 276 | 303 | { |
|---|
| 277 | 304 | |
|---|
| … | … | |
| 281 | 308 | remove (oldElement); |
|---|
| 282 | 309 | add (newElement); |
|---|
| 283 | | return 1; |
|---|
| | 310 | return true; |
|---|
| 284 | 311 | } |
|---|
| 285 | | return 0; |
|---|
| | 312 | return false; |
|---|
| 286 | 313 | } |
|---|
| 287 | 314 | |
|---|
| … | … | |
| 324 | 351 | ************************************************************************/ |
|---|
| 325 | 352 | |
|---|
| 326 | | public uint remove (IContainer!(V) e, bool all=false) |
|---|
| | 353 | public uint remove (IContainer!(V) e) |
|---|
| 327 | 354 | { |
|---|
| 328 | 355 | uint c; |
|---|
| 329 | 356 | foreach (value; e) |
|---|
| 330 | | if (remove (value, all)) |
|---|
| | 357 | if (remove (value)) |
|---|
| 331 | 358 | ++c; |
|---|
| 332 | 359 | return c; |
|---|
Download in other formats:
|
 |
 |
|
 |
Copyright © 2006-2008 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic