Rev | Line | |
---|
[14777] | 1 | using System.Collections.Generic;
|
---|
| 2 |
|
---|
| 3 | namespace TestPooling.DirtyList {
|
---|
| 4 | public class PushStack2<T> {
|
---|
| 5 | private readonly List<List<T>> items = new List<List<T>>();
|
---|
| 6 | private bool IsEnabled { get; set; }
|
---|
| 7 |
|
---|
| 8 | public PushStack2() {
|
---|
| 9 | IsEnabled = true;
|
---|
| 10 | }
|
---|
| 11 |
|
---|
| 12 | public void Push(T item) {
|
---|
| 13 | if (!IsEnabled) return;
|
---|
| 14 |
|
---|
[14908] | 15 | items[items.Count - 1].Add(item);
|
---|
[14777] | 16 | }
|
---|
| 17 |
|
---|
| 18 | public void PushRange(IEnumerable<T> items) {
|
---|
| 19 | if (!IsEnabled) return;
|
---|
| 20 |
|
---|
| 21 | this.items.Add(new List<T>(items));
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | public T Pop() {
|
---|
| 25 | var container = items[items.Count - 1];
|
---|
| 26 |
|
---|
| 27 | if (container.Count == 1) {
|
---|
| 28 | items.RemoveAt(items.Count - 1);
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | var item = container[container.Count - 1];
|
---|
| 32 | container.RemoveAt(container.Count - 1);
|
---|
| 33 |
|
---|
| 34 | return item;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | public void Clear() {
|
---|
[14908] | 38 | items.Clear();
|
---|
[14777] | 39 | }
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.